Beispiel #1
0
function setup_database($new = false)
{
    global $MYSQL_SERVER;
    global $MYSQL_USER;
    global $MYSQL_PASSWORD;
    global $MYSQL_DATABASE;
    echo "= DATABASE SETUP =" . PHP_EOL . PHP_EOL;
    $conn = mysql_connect($MYSQL_SERVER, $MYSQL_USER, $MYSQL_PASSWORD);
    if ($new) {
        mysql_query("DROP DATABASE {$MYSQL_DATABASE}");
        echo "Database {$database} dropped." . PHP_EOL;
    }
    mysql_query("CREATE DATABASE IF NOT EXISTS {$MYSQL_DATABASE}") or die(mysql_error());
    echo "Database {$MYSQL_DATABASE} created." . PHP_EOL;
    mysql_select_db($MYSQL_DATABASE, $conn);
    mysql_set_charset("utf8");
    if ($new) {
        $dir = "database/";
        if (is_dir($dir)) {
            if ($handle = opendir($dir)) {
                while (false !== ($file = readdir($handle))) {
                    if (!is_dir($file) && !endsWith($file, "_inserts.sql")) {
                        create_table($file);
                    }
                }
            }
        }
        insert_languages();
        echo "Tables for {$MYSQL_DATABASE} created." . PHP_EOL;
    }
}
function check_cli_args($options)
{
    if (array_key_exists('u', $options) && array_key_exists('p', $options) && array_key_exists('h', $options)) {
        if (array_key_exists("create_table", $options)) {
            if (array_key_exists("file", $options) || array_key_exists("dry_run", $options)) {
                echo "\nCommand format not correct\n\n";
                echo_usage();
            } else {
                echo "\nCreating users table\n\n";
                create_table($options);
            }
        } else {
            if (array_key_exists("file", $options) && array_key_exists("dry_run", $options)) {
                echo "\nImporting file and doing dry run\n\n";
                $dry_run = true;
                csv_reader($dry_run, $options);
            } else {
                if (array_key_exists("file", $options)) {
                    echo "\nImporting file and doing commit\n\n";
                    $dry_run = false;
                    csv_reader($dry_run, $options);
                }
            }
        }
    } else {
        if (array_key_exists("help", $options)) {
            echo_usage();
        } else {
            echo "\nCommand format not correct\n\n";
            echo_usage();
        }
    }
}
Beispiel #3
0
function xmldb_artefact_calendar_upgrade($oldversion = 0)
{
    if ($oldversion < 2013062404) {
        $table = new XMLDBTable('artefact_calendar_reminder');
        drop_table($table);
        $table->addFieldInfo('user', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL);
        $table->addFieldInfo('reminder_type', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL);
        $table->addFieldInfo('reminder_date', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '-1', null);
        $table->addKeyInfo('reminder_pk', XMLDB_KEY_PRIMARY, array('user'));
        if (!create_table($table)) {
            throw new SQLException($table . " could not be created, check log for errors.");
        }
        execute_sql('ALTER TABLE {artefact_calendar_calendar} DROP COLUMN {reminder_status}');
    }
    if ($oldversion < 2013062501) {
        execute_sql('ALTER TABLE {artefact_calendar_calendar} change {reminder_date} {reminder_date} int(4) NOT NULL;');
    }
    if ($oldversion < 2013063001) {
        $table = new XMLDBTable('artefact_calendar_event');
        $table->addFieldInfo('eventid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL);
        $table->addFieldInfo('begin', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL);
        $table->addFieldInfo('end', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL);
        $table->addFieldInfo('whole_day', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL);
        $table->addFieldInfo('repeat_type', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL);
        $table->addFieldInfo('repeats_every', XMLDB_TYPE_INTEGER, '3', null, XMLDB_NOTNULL);
        $table->addFieldInfo('end_date', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL);
        $table->addFieldInfo('ends_after', XMLDB_TYPE_INTEGER, '3', null, XMLDB_NOTNULL);
        $table->addKeyInfo('event_pk', XMLDB_KEY_PRIMARY, array('eventid'));
        if (!create_table($table)) {
            throw new SQLException($table . " could not be created, check log for errors.");
        }
    }
    return true;
}
function sendgrid_sga_data_api()
{
    header("Content-Type: application/json");
    if ($_POST['api_key'] != get_option("sendgrid_sga_apikey")) {
        $output = array("error" => true, "message" => "Unauthenticated.");
        echo json_encode($output);
        die;
    }
    $period_start = create_start_time($_POST['period_start'], true);
    $period_end = create_end_time($_POST['period_end'], true);
    create_table($period_start, $period_end);
    $output = array("error" => true, "message" => "Unknown error.");
    $body = array();
    if ($_POST['data'] == "users") {
        $top_users = get_top_users();
        foreach ($top_users as $rank => $user_info) {
            $formatted_user_info = format_user_info($user_info);
            $body[] = array("raw" => array("post_author" => get_post_author($user_info->post_author), "mantime" => (int) $user_info->mantime, "visits" => (int) $user_info->visits, "pageviews" => (int) $user_info->pageviews, "avg_time_on_page" => (double) $user_info->avg_time_on_page, "entrance_rate" => (double) $user_info->entrance_rate, "exit_rate" => (double) $user_info->exit_rate), "formatted" => $formatted_user_info);
        }
        $output = array("error" => false, "body" => $body, "period_start" => $period_start, "period_end" => $period_end);
    } elseif ($_POST['data'] == "posts") {
        $top_posts = get_top_posts();
        foreach ($top_posts as $rank => $post_info) {
            $formatted_post_info = format_post_info($post_info);
            $body[] = array("raw" => array("guid" => $post_info->guid, "post_title" => $post_info->post_title, "post_author" => get_post_author($post_info->post_author), "mantime" => (int) $post_info->mantime, "visits" => (int) $post_info->visits, "pageviews" => (int) $post_info->pageviews, "avg_time_on_page" => (double) $post_info->avg_time_on_page, "entrance_rate" => (double) $post_info->entrance_rate, "exit_rate" => (double) $post_info->exit_rate), "formatted" => $formatted_post_info);
        }
        $output = array("error" => false, "body" => $body, "period_start" => $period_start, "period_end" => $period_end);
    } else {
        $output = array("error" => true, "message" => "Data attribute not understood, please provide either users or posts");
    }
    echo json_encode($output);
    die;
}
Beispiel #5
0
function xmldb_blocktype_taggedposts_upgrade($oldversion = 0)
{
    if ($oldversion < 2015011500) {
        $table = new XMLDBTable('blocktype_taggedposts_tags');
        $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL, XMLDB_SEQUENCE);
        $table->addFieldInfo('block_instance', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL);
        $table->addFieldInfo('tag', XMLDB_TYPE_CHAR, 128, null, XMLDB_NOTNULL);
        $table->addFieldInfo('tagtype', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL);
        $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
        $table->addIndexInfo('tagtagtypeix', XMLDB_INDEX_NOTUNIQUE, array('tag', 'tagtype'));
        if (!table_exists($table)) {
            create_table($table);
            $rs = get_recordset('block_instance', 'blocktype', 'taggedposts', 'id', 'id, configdata');
            while ($bi = $rs->FetchRow()) {
                // Each block will have only one tag (because we combined this upgrade block
                // with the upgrade block for the "multiple tags" enhancement.
                $configdata = unserialize($bi['configdata']);
                if (!empty($configdata['tagselect'])) {
                    $todb = new stdClass();
                    $todb->block_instance = $bi['id'];
                    $todb->tag = $configdata['tagselect'];
                    $todb->tagtype = PluginBlocktypeTaggedposts::TAGTYPE_INCLUDE;
                    insert_record('blocktype_taggedposts_tags', $todb);
                }
            }
        }
    }
    return true;
}
 public function up()
 {
     // Get database handle
     $dbh = $this->getdbh();
     // Check if database is already migrated
     try {
         // This will cause an Exception if not migrated
         $dbh->query("SELECT VolumeName FROM diskreport");
         return TRUE;
     } catch (Exception $e) {
         // Not migrated, continue..
     }
     // Create temp table
     create_table($this);
     // Copy data into temp
     $now = time();
     $sql = "INSERT INTO diskreport_temp \n\t\t\t\t\tSELECT id, serial_number, TotalSize, FreeSpace, Percentage, SMARTStatus, CASE WHEN SolidState = 1 THEN 'ssd' ELSE 'hdd' END, 'unknown', 1, '/', 'Unknown', -1, {$now} FROM diskreport";
     $this->exec($sql);
     $sql = "DROP table diskreport";
     $this->exec($sql);
     $sql = "ALTER TABLE diskreport_temp RENAME TO diskreport";
     $this->exec($sql);
     // Build indexes
     $this->tablename = 'diskreport';
     $this->idx[] = array('serial_number');
     $this->idx[] = array('VolumeType');
     $this->idx[] = array('MountPoint');
     $this->idx[] = array('VolumeName');
     $this->set_indexes();
 }
function xmldb_block_ajax_marking_upgrade($oldversion = 0)
{
    //echo "oldversion: ".$oldversion;
    global $CFG, $THEME, $db;
    $result = true;
    /// And upgrade begins here. For each one, you'll need one
    /// block of code similar to the next one. Please, delete
    /// this comment lines once this file start handling proper
    /// upgrade code.
    if ($result && $oldversion < 2007052901) {
        //New version in version.php
        /// Define table block_ajax_marking to be created
        $table = new XMLDBTable('block_ajax_marking');
        /// Adding fields to table block_ajax_marking
        $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
        $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', null, null, null, null, null, null);
        $table->addFieldInfo('assessmenttype', XMLDB_TYPE_CHAR, '40', null, null, null, null, null, null);
        $table->addFieldInfo('assessmentid', XMLDB_TYPE_INTEGER, '10', null, null, null, null, null, null);
        $table->addFieldInfo('showhide', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, null, '1');
        $table->addFieldInfo('groups', XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null);
        /// Adding keys to table block_ajax_marking
        $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
        $table->addKeyInfo('useridkey', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
        /// Launch create table for block_ajax_marking
        $result = $result && create_table($table);
    }
    // run this on every upgrade.
    AMB_update_modules();
    return $result;
}
Beispiel #8
0
function format_sql($sql)
{
    global $db;
    $sql = str_replace("\r", "\n", $sql);
    $ret = array();
    $num = 0;
    foreach (explode(";\n", trim($sql)) as $query) {
        $queries = explode("\n", trim($query));
        foreach ($queries as $query) {
            $ret[$num] .= $query[0] == '#' || $query[0] . $query[1] == '--' ? '' : $query;
        }
        $num++;
    }
    unset($sql);
    foreach ($ret as $query) {
        $query = trim($query);
        if ($query) {
            if (substr($query, 0, 12) == 'CREATE TABLE') {
                //$name = preg_replace("/CREATE TABLE ([a-z0-9_]+) .*/is", "\\1", $query);
                //echo '创建表:'.$name.' ... <font color="#0000EE">'.$lang['succeed'].'</font><br>';
                $db->query(create_table($query));
            } else {
                $db->query($query);
            }
        }
    }
}
Beispiel #9
0
/**
 * ELIS(TM): Enterprise Learning Intelligence Suite
 * Copyright (C) 2008-2012 Remote Learner.net Inc http://www.remote-learner.net
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @package    elis
 * @subpackage curriculummanagement
 * @author     Remote-Learner.net Inc
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @copyright  (C) 2008-2012 Remote Learner.net Inc http://www.remote-learner.net
 *
 */
function xmldb_crlm_cluster_classification_upgrade($oldversion = 0)
{
    global $CFG, $THEME, $db;
    $result = true;
    if ($result && $oldversion < 2010080502) {
        /// Define table crlm_cluster_classification to be created
        $table = new XMLDBTable('crlm_cluster_classification');
        /// Adding fields to table crlm_cluster_classification
        $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
        $table->addFieldInfo('shortname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
        $table->addFieldInfo('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
        $table->addFieldInfo('params', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
        /// Adding keys to table crlm_cluster_classification
        $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
        $table->addKeyInfo('shortname_idx', XMLDB_KEY_UNIQUE, array('shortname'));
        /// Launch create table for crlm_cluster_classification
        $result = $result && create_table($table);
    }
    if ($result && $oldversion < 2010080503) {
        require_once $CFG->dirroot . '/curriculum/lib/customfield.class.php';
        require_once $CFG->dirroot . '/curriculum/plugins/cluster_classification/lib.php';
        require_once $CFG->dirroot . '/curriculum/plugins/cluster_classification/clusterclassification.class.php';
        $field = new field(field::get_for_context_level_with_name('cluster', CLUSTER_CLASSIFICATION_FIELD));
        // make sure we're set as owner
        if (!isset($field->owners['cluster_classification'])) {
            $owner = new field_owner();
            $owner->fieldid = $field->id;
            $owner->plugin = 'cluster_classification';
            $owner->add();
        }
        // make sure we have a default value set
        if (!field_data::get_for_context_and_field(NULL, $field)) {
            field_data::set_for_context_and_field(NULL, $field, 'regular');
        }
        $default = new clusterclassification();
        $default->shortname = 'regular';
        $default->name = get_string('cluster', 'block_curr_admin');
        $default->param_autoenrol_curricula = 1;
        $default->param_autoenrol_tracks = 1;
        $default->add();
    }
    // make sure 'manual' is an owner
    if ($result && $oldversion < 2010080504) {
        require_once $CFG->dirroot . '/curriculum/lib/customfield.class.php';
        require_once $CFG->dirroot . '/curriculum/plugins/cluster_classification/lib.php';
        require_once $CFG->dirroot . '/curriculum/plugins/cluster_classification/clusterclassification.class.php';
        $field = new field(field::get_for_context_level_with_name('cluster', CLUSTER_CLASSIFICATION_FIELD));
        $owner = new field_owner();
        $owner->fieldid = $field->id;
        $owner->plugin = 'manual';
        $owner->param_view_capability = '';
        $owner->param_edit_capability = 'moodle/user:update';
        $owner->param_control = 'menu';
        $owner->param_options_source = 'cluster_classifications';
        $owner->add();
    }
    return $result;
}
 public function execute()
 {
     global $settings;
     global $APP;
     if ($APP['db']->connect()) {
         if ($APP['db']->kind == "mysql") {
             $APP['db']->query("CREATE TABLE IF NOT EXISTS assign_hf (\n  id_user varchar(50) NOT NULL DEFAULT 'undefined',\n  hf_server varchar(100) NOT NULL DEFAULT 'undefined',\n  PRIMARY KEY (id_user,hf_server)\n) ENGINE=InnoDB DEFAULT CHARSET=latin1;");
             $APP['db']->query("CREATE TABLE IF NOT EXISTS assign_server (\n  id_user varchar(50) NOT NULL DEFAULT 'undefined',\n  server_hf varchar(100) NOT NULL DEFAULT 'undefined',\n  PRIMARY KEY (id_user,server_hf)\n) ENGINE=InnoDB DEFAULT CHARSET=latin1;");
             $APP['db']->query("ALTER TABLE `user_server` ADD `int_online` VARCHAR(1) NOT NULL DEFAULT '1' AFTER  `is_busy`");
         }
         if ($APP['db']->kind == "mssql") {
             $APP['db']->query("SET ANSI_NULLS ON;\nSET QUOTED_IDENTIFIER ON;\nSET ANSI_PADDING ON;\nCREATE TABLE [dbo].[assign_hf](\n        [id_user] [varchar](50) NOT NULL DEFAULT ('undefined'),\n        [hf_server] [varchar](100) NOT NULL DEFAULT ('undefined'),\n CONSTRAINT [primary pkey_assign_hf] PRIMARY KEY CLUSTERED\n(\n        [id_user] ASC,\n        [hf_server] ASC\n)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]\n) ON [PRIMARY];\nSET ANSI_PADDING OFF;");
             $APP['db']->query("SET ANSI_NULLS ON;\nSET QUOTED_IDENTIFIER ON;\nSET ANSI_PADDING ON;\nCREATE TABLE [dbo].[assign_server](\n        [id_user] [varchar](50) NOT NULL DEFAULT ('undefined'),\n        [server_hf] [varchar](100) NOT NULL DEFAULT ('undefined'),\n CONSTRAINT [primary pkey_assign_server] PRIMARY KEY CLUSTERED\n(\n        [id_user] ASC,\n        [server_hf] ASC\n)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]\n) ON [PRIMARY];\nSET ANSI_PADDING OFF;\n");
             $APP['db']->query("ALTER TABLE dbo.user_server ADD \nint_online varchar(1) NOT NULL \nDEFAULT ('1') \nGO \nEXEC user_server;\nGO");
         }
         if ($APP['db']->kind == "oracle") {
             $query_string = "  CREATE TABLE 'DBNAME'.'ASSIGN_HF'\n   (    'ID_USER' VARCHAR2(50 BYTE) DEFAULT 'undefined',\n        'HF_SERVER' VARCHAR2(100 BYTE) DEFAULT 'undefined',\n   ) SEGMENT CREATION IMMEDIATE\n  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING\n  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645\n  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)\n  TABLESPACE 'USERS' ;\n\n  CREATE UNIQUE INDEX 'DBNAME'.'PKEY_ASSIGN_HF' ON 'DBNAME'.'ASSIGN_HF' ('ID_USER', 'HF_SERVER')\n  PCTFREE 10 INITRANS 2 MAXTRANS 255\n  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645\n  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)\n  TABLESPACE 'USERS' ;\n\n  ALTER TABLE 'DBNAME'.'ASSIGN_HF' ADD CONSTRAINT 'PKEY_ASSIGN_HF' PRIMARY KEY ('ID_USER', 'HF_SERVER')\n  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255\n  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645\n  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)\n  TABLESPACE 'USERS'  ENABLE;\n  ALTER TABLE 'DBNAME'.'ASSIGN_HF' MODIFY ('ID_USER' NOT NULL ENABLE);\n  ALTER TABLE 'DBNAME'.'ASSIGN_HF' MODIFY ('HF_SERVER' NOT NULL ENABLE);";
             $query_string = str_replace("(SEMICOLON)", ";", $query_string);
             $query_string = str_replace("DBNAME", strtoupper($APP['db']->dbname), $query_string);
             $query_string = str_replace("USERNAME", $APP['db']->auth1, $query_string);
             $APP['db']->query($query_string);
             $query_string = "  CREATE TABLE 'DBNAME'.'ASSIGN_SERVER'\n   (    'ID_USER' VARCHAR2(50 BYTE) DEFAULT 'undefined',\n        'SERVER_HF' VARCHAR2(100 BYTE) DEFAULT 'undefined',\n   ) SEGMENT CREATION IMMEDIATE\n  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING\n  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645\n  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)\n  TABLESPACE 'USERS' ;\n\n  CREATE UNIQUE INDEX 'DBNAME'.'PKEY_ASSIGN_SERVER' ON 'DBNAME'.'ASSIGN_SERVER' ('ID_USER', 'SERVER_HF')\n  PCTFREE 10 INITRANS 2 MAXTRANS 255\n  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645\n  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)\n  TABLESPACE 'USERS' ;\n\n  ALTER TABLE 'DBNAME'.'ASSIGN_SERVER' ADD CONSTRAINT 'PKEY_ASSIGN_SERVER' PRIMARY KEY ('ID_USER', 'SERVER_HF')\n  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255\n  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645\n  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)\n  TABLESPACE 'USERS'  ENABLE;\n  ALTER TABLE 'DBNAME'.'ASSIGN_SERVER' MODIFY ('ID_USER' NOT NULL ENABLE);\n  ALTER TABLE 'DBNAME'.'ASSIGN_SERVER' MODIFY ('SERVER_HF' NOT NULL ENABLE);";
             $query_string = str_replace("(SEMICOLON)", ";", $query_string);
             $query_string = str_replace("DBNAME", strtoupper($APP['db']->dbname), $query_string);
             $query_string = str_replace("USERNAME", $APP['db']->auth1, $query_string);
             $APP['db']->query($query_string);
             $APP['db']->query("ALTER TABLE\n  user_server \nADD\n  int_online varchar2(1) DEFAULT '1' NOT NULL;");
         }
         if ($APP['db']->kind == "postgres") {
             $APP['db']->query("CREATE TABLE assign_hf (\n    id_user character varying(50) DEFAULT 'undefined'::character varying NOT NULL,\n    hf_server character varying(100) DEFAULT 'undefined'::character varying NOT NULL\n);\nALTER TABLE public.assign_hf OWNER TO USERNAME;\nALTER TABLE ONLY assign_hf ADD CONSTRAINT assign_hf_pkey PRIMARY KEY (id_user, hf_server);");
             $APP['db']->query("CREATE TABLE assign_server (\n    id_user character varying(50) DEFAULT 'undefined'::character varying NOT NULL,\n    server_hf character varying(100) DEFAULT 'undefined'::character varying NOT NULL\n);\nALTER TABLE public.assign_server OWNER TO USERNAME;\nALTER TABLE ONLY assign_server ADD CONSTRAINT assign_server_pkey PRIMARY KEY (id_user, server_hf);");
             $APP['db']->query("ALTER TABLE user_server ADD COLUMN int_online character varying(1) DEFAULT '1'::character varying NOT NULL");
         }
         if ($APP['db']->kind == "mongodb") {
             try {
                 $c = $APP['db']->db->selectDB($APP['db']->dbname)->createCollection("assign_hf");
                 $c->ensureIndex(array("id_user" => 1, "hf_server" => 1), array("unique" => 1, "dropDups" => 1));
             } catch (Exception $e) {
                 print_r($e);
             }
             try {
                 $c = $APP['db']->db->selectDB($APP['db']->dbname)->createCollection("assign_server");
                 $c->ensureIndex(array("id_user" => 1, "server_hf" => 1), array("unique" => 1, "dropDups" => 1));
             } catch (Exception $e) {
                 print_r($e);
             }
         }
         if ($APP['db']->kind == "dynamodb") {
             $_POST['substep'] = -1;
             include "schemas/db-schema-dynamodb.sql";
             create_table("assign_hf", false, "id_user", "hf_server");
             echo " ";
             create_table("assign_server", false, "id_user", "server_hf");
             echo " ";
         }
     }
 }
Beispiel #11
0
function zinchinfo()
{
    $svn_table = create_table(zinchInfo_revision());
    $php_server_table = create_table($_SERVER);
    $final_output = '<div class="center_z">';
    $final_output = $final_output . css_style() . create_table_header();
    $final_output = $final_output . "<br>" . $svn_table;
    $final_output = $final_output . "<br>" . $php_server_table;
    $final_output = $final_output . '</div>';
    return $final_output;
}
Beispiel #12
0
function wrsqz_create_table($table)
{
    if (table_exists($table, true, false)) {
        return wrsqz_update_table($table);
    } else {
        if (create_table($table, true, false)) {
            return CREATED_TABLE;
        } else {
            return DB_ERROR;
        }
    }
}
Beispiel #13
0
 function _run_sql($sqls)
 {
     if (is_string($sqls)) {
         $sqls = get_sql($sqls);
     }
     if (!is_array($sqls)) {
         return true;
     }
     // 检查可能在某次补丁中已经添加过的字段
     // 检查哪些字段
     $check_fields = array('ecm_order' => array('pay_alter'), 'ecm_store' => array('enable_radar', 'enable_groupbuy'));
     // 哪些在数据库中已经存在
     $exist_fields = array();
     foreach ($check_fields as $table => $fields) {
         $result = $this->db->query("SELECT * FROM `{$table}` limit 1");
         $i = 0;
         while ($i < mysql_num_fields($result)) {
             $meta = mysql_fetch_field($result);
             if (in_array($meta->name, $fields)) {
                 $exist_fields[$table][] = $meta->name;
             }
             $i++;
         }
     }
     foreach ($sqls as $sql) {
         $need_exec = true;
         foreach ($exist_fields as $table => $fields) {
             foreach ($fields as $field) {
                 $pattern = "/alter\\s+table\\s+`?{$table}`?\\s+add\\s+`?{$field}`?\\s+/Uis";
                 if (preg_match($pattern, $sql)) {
                     // 该sql语句不需要执行
                     $need_exec = false;
                     break;
                 }
             }
         }
         if ($need_exec) {
             substr($sql, 0, 12) == 'CREATE TABLE' && ($sql = create_table($sql));
             $query = $this->db->query($sql, 'SILENT');
             if (!$query) {
                 $this->_error($this->db->error());
                 return false;
             }
         }
     }
     return true;
 }
 public function execute()
 {
     global $APP;
     if ($APP['db']->connect()) {
         if ($APP['db']->kind == "mysql") {
             $query_string = "CREATE TABLE IF NOT EXISTS user_server_service (\n  id_user_server varchar(50) NOT NULL DEFAULT 'undefined',\n  service_name varchar(50) NOT NULL DEFAULT 'undefined',\n  service_enabled varchar(1) NOT NULL DEFAULT '0',\n  PRIMARY KEY (id_user_server,service_name)\n) ENGINE=InnoDB DEFAULT CHARSET=latin1;";
             $query_string = str_replace("(SEMICOLON)", ";", $query_string);
             $query_string = str_replace("DBNAME", strtoupper($APP['db']->dbname), $query_string);
             $query_string = str_replace("USERNAME", $APP['db']->auth1, $query_string);
             $APP['db']->query($query_string);
         }
         if ($APP['db']->kind == "mssql") {
             $query_string = "SET ANSI_NULLS ON;\nSET QUOTED_IDENTIFIER ON;\nSET ANSI_PADDING ON;\nCREATE TABLE [dbo].[user_server_service](\n\t[id_user_server] [varchar](50) NOT NULL DEFAULT ('undefined'),\n\t[service_name] [varchar](50) NOT NULL DEFAULT ('undefined'),\n\t[service_enabled] [varchar](1) NOT NULL DEFAULT ('0'),\n CONSTRAINT [primary pkey_user_server_service] PRIMARY KEY CLUSTERED \n(\n\t[id_user_server] ASC,\n\t[service_name] ASC\n)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]\n) ON [PRIMARY];\nSET ANSI_PADDING OFF;";
             $query_string = str_replace("(SEMICOLON)", ";", $query_string);
             $query_string = str_replace("DBNAME", strtoupper($APP['db']->dbname), $query_string);
             $query_string = str_replace("USERNAME", $APP['db']->auth1, $query_string);
             $APP['db']->query($query_string);
         }
         if ($APP['db']->kind == "oracle") {
             $query_string = "  CREATE TABLE 'DBNAME'.'USER_SERVER_SERVICE'\n   (    'ID_USER_SERVER' VARCHAR2(50 BYTE) DEFAULT '',\n        'SERVICE_NAME' VARCHAR2(50 BYTE) DEFAULT '',\n        'SERVICE_ENABLED' VARCHAR2(1 BYTE) DEFAULT '0',\n   ) SEGMENT CREATION IMMEDIATE\n  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING\n  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645\n  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)\n  TABLESPACE 'USERS' ;\n\n  CREATE UNIQUE INDEX 'DBNAME'.'PKEY_USER_SERVER_SERVICE' ON 'DBNAME'.'USER_SERVER_SERVICE' ('ID_USER_SERVER', 'SERVICE_NAME')\n  PCTFREE 10 INITRANS 2 MAXTRANS 255\n  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645\n  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)\n  TABLESPACE 'USERS' ;\n\n  ALTER TABLE 'DBNAME'.'USER_SERVER_SERVICE' ADD CONSTRAINT 'PKEY_USER_SERVER_SERVICE' PRIMARY KEY ('ID_USER_SERVER', 'SERVICE_NAME')\n  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255\n  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645\n  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)\n  TABLESPACE 'USERS'  ENABLE;\n  ALTER TABLE 'DBNAME'.'USER_SERVER_SERVICE' MODIFY ('ID_USER_SERVER' NOT NULL ENABLE);\n  ALTER TABLE 'DBNAME'.'USER_SERVER_SERVICE' MODIFY ('SERVICE_NAME' NOT NULL ENABLE);\n  ALTER TABLE 'DBNAME'.'USER_SERVER_SERVICE' MODIFY ('SERVICE_ENABLED' NOT NULL ENABLE);";
             $query_string = str_replace("(SEMICOLON)", ";", $query_string);
             $query_string = str_replace("DBNAME", strtoupper($APP['db']->dbname), $query_string);
             $query_string = str_replace("USERNAME", $APP['db']->auth1, $query_string);
             $APP['db']->query($query_string);
         }
         if ($APP['db']->kind == "postgres") {
             $query_string = "CREATE TABLE user_server_service (\n    id_user_server character varying(50) DEFAULT 'undefined'::character varying NOT NULL,\n    service_name character varying(50) DEFAULT 'undefined'::character varying NOT NULL,\n    service_enabled character varying(1) DEFAULT '0'::character varying NOT NULL\n);\nALTER TABLE public.user_server_service OWNER TO USERNAME;\nALTER TABLE ONLY user_server_service ADD CONSTRAINT user_server_service_pkey PRIMARY KEY (id_user_server, service_name);";
             $query_string = str_replace("(SEMICOLON)", ";", $query_string);
             $query_string = str_replace("DBNAME", strtoupper($APP['db']->dbname), $query_string);
             $query_string = str_replace("USERNAME", $APP['db']->auth1, $query_string);
             $APP['db']->query($query_string);
         }
         if ($APP['db']->kind == "mongodb") {
             try {
                 $c = $APP['db']->db->selectDB($APP['db']->dbname)->createCollection("user_server_service");
                 $c->ensureIndex(array("id_user_server" => 1, "service_name" => 1), array("unique" => 1, "dropDups" => 1));
             } catch (Exception $e) {
                 print_r($e);
             }
         }
         if ($APP['db']->kind == "dynamodb") {
             $_POST['substep'] = -1;
             include "schemas/db-schema-dynamodb.sql";
             create_table("user_server_service", false, "id_user_server", "service_name");
         }
     }
 }
Beispiel #15
0
function xmldb_qtype_rqp_upgrade($oldversion = 0)
{
    global $CFG, $THEME, $db;
    $result = true;
    if ($result && $oldversion < 2006032201) {
        $table = new XMLDBTable('question_rqp_servers');
        $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, 10, XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE);
        $table->addFieldInfo('typeid', XMLDB_TYPE_INTEGER, 10, XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, 0);
        $table->addFieldInfo('url', XMLDB_TYPE_CHAR, 255);
        $table->addFieldInfo('can_render', XMLDB_TYPE_INTEGER, 2, XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, 0);
        $table->addFieldInfo('can_author', XMLDB_TYPE_INTEGER, 2, XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, 0);
        $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
        $table->addKeyInfo('typeid', XMLDB_KEY_FOREIGN, array('typeid'), 'rqp_types', array('id'));
        $result = $result && create_table($table);
    }
    return $result;
}
Beispiel #16
0
function xmldb_artefact_blog_upgrade($oldversion = 0)
{
    if ($oldversion < 2008101602) {
        $table = new XMLDBTable('artefact_blog_blogpost_file_pending');
        $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, 10, XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
        $table->addFieldInfo('oldextension', XMLDB_TYPE_TEXT, null);
        $table->addFieldInfo('filetype', XMLDB_TYPE_TEXT, null);
        $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
        create_table($table);
    }
    if ($oldversion < 2009033100) {
        $bloguploadbase = get_config('dataroot') . 'artefact/blog/uploads/';
        if (is_dir($bloguploadbase)) {
            if ($basedir = opendir($bloguploadbase)) {
                while (false !== ($sessionupload = readdir($basedir))) {
                    if ($sessionupload != "." && $sessionupload != "..") {
                        $sessionupload = $bloguploadbase . $sessionupload;
                        $subdir = opendir($sessionupload);
                        while (false !== ($uploadfile = readdir($subdir))) {
                            if ($uploadfile != "." && $uploadfile != "..") {
                                $uploadfile = $sessionupload . '/' . $uploadfile;
                                unlink($uploadfile);
                            }
                        }
                        closedir($subdir);
                        rmdir($sessionupload);
                    }
                }
            }
            @rmdir($bloguploadbase);
        }
    }
    if ($oldversion < 2009081800) {
        $subscription = (object) array('plugin' => 'blog', 'event' => 'createuser', 'callfunction' => 'create_default_blog');
        ensure_record_exists('artefact_event_subscription', $subscription, $subscription);
    }
    if ($oldversion < 2011091400) {
        delete_records('artefact_cron', 'plugin', 'blog', 'callfunction', 'clean_post_files');
    }
    if ($oldversion < 2015011500) {
        delete_records('institution_config', 'field', 'progressbaritem_blog_blog');
    }
    return true;
}
/**
 * Update plugin.
 *
 * @param int $oldversion the version we are upgrading from
 * @return bool result
 */
function xmldb_auth_oidc_upgrade($oldversion)
{
    $result = true;
    if ($result && $oldversion < 2009072001) {
        // Create the core services tables
        $table = new \XMLDBTable('auth_oidc_state');
        $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
        $table->addFieldInfo('sesskey', XMLDB_TYPE_CHAR, 10, null, null);
        $table->addFieldInfo('state', XMLDB_TYPE_CHAR, 15, null, null);
        $table->addFieldInfo('nonce', XMLDB_TYPE_CHAR, 15, null, null);
        $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, 15, null, null);
        $table->addFieldInfo('additionaldata', XMLDB_TYPE_TEXT, null);
        $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
        $table->addIndexInfo('state', XMLDB_INDEX_NOTUNIQUE, array('state'));
        $table->addIndexInfo('timecreated', XMLDB_INDEX_NOTUNIQUE, array('timecreated'));
        create_table($table);
    }
    return $result;
}
/**
 * Logs an event to make sure it's not triggered again
 * @params:
 *		$event						:array
 *	 		$event['issue_id']		:integer, the id of the issue to be logeed with the event
 *			$event['initiative_id']	:integer, the id of the initiative to be looged with the event
 *			$event['job']			:string, the job that handled the issue
 * @returns true on success, dies otherwise
 */
function log_event($event)
{
    global $db_events_table;
    //the events table's name for each bot is defined in update_twitter_bot.php right before the bot is processed
    $time = time();
    if (!table_exists($db_events_table)) {
        create_table($db_events_table, 'time INT, issue_id INT, initiative_id INT, job CHAR(80)');
    }
    $query = "INSERT INTO {$db_events_table} (time, issue_id, initiative_id, job) VALUES({$time}, {$event['issue_id']} , {$event['initiative_id']} , '{$event['job']}')";
    $result = mysql_query($query);
    $error = mysql_errno();
    if ($error != 0) {
        log_this("error: tried to log event ({$event['issue_id']} , {$event['issue_id']}, '{$event['job']})", mysql_error() . ": \n" . $query);
        die("Unable to log event. MySQL error: " . $error);
    } else {
        log_this("success: logged event ({$event['issue_id']} ,{$event['initiative_id']}, '{$event['job']})");
        return true;
    }
}
function xmldb_format_fn_upgrade($oldversion = 0)
{
    global $CFG, $THEME, $db;
    $result = true;
    if ($result && $oldversion < 2007060102) {
        //New version in version.php
        $table = new XMLDBTable('fn_coursemodule_extra');
        $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null, null);
        $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'id');
        $table->addFieldInfo('cmid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'courseid');
        $table->addFieldInfo('hideingradebook', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'cmid');
        $table->addFieldInfo('mandatory', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'hideingradebook');
        $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
        $table->addIndexInfo('courseid', XMLDB_INDEX_NOTUNIQUE, array('courseid'));
        $table->addIndexInfo('cmid', XMLDB_INDEX_NOTUNIQUE, array('cmid'));
        $result = create_table($table);
    }
    return $result;
}
/**
 * Collapsed Topics Information
 *
 * A topic based format that solves the issue of the 'Scroll of Death' when a course has many topics. All topics
 * except zero have a toggle that displays that topic. One or more topics can be displayed at any given time.
 * Toggles are persistent on a per browser session per course basis but can be made to persist longer by a small
 * code change. Full installation instructions, code adaptions and credits are included in the 'Readme.txt' file.
 *
 * @package    course/format
 * @subpackage topcoll
 * @version    See the value of '$plugin->version' in below.
 * @copyright  &copy; 2009-onwards G J Barnard in respect to modifications of standard topics format.
 * @author     G J Barnard - gjbarnard at gmail dot com and {@link http://moodle.org/user/profile.php?id=442195}
 * @link       http://docs.moodle.org/en/Collapsed_Topics_course_format
 * @license    http://www.gnu.org/copyleft/gpl.html GNU Public License
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
function xmldb_format_topcoll_upgrade($oldversion = 0)
{
    global $CFG, $THEME, $db;
    $result = true;
    if ($result && $oldversion < 2012030200) {
        // Define table format_topcoll_layout.
        $table = new XMLDBTable('format_topcoll_layout');
        // Drop it if it existed before
        drop_table($table, true, false);
        // Adding fields.
        $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
        $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, '0', null);
        $table->addFieldInfo('layoutelement', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, '1', null);
        $table->addFieldInfo('layoutstructure', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, '1', null);
        // Adding key.
        $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
        // Create table.
        $result = $result && create_table($table);
    }
    return $result;
}
function table()
{
    $error = null;
    $page = CurrentPageName();
    $tpl = new templates();
    $users = new usersMenus();
    $sock = new sockets();
    $q = new mysql_squid_builder();
    if (!$q->TABLE_EXISTS("artica_caches")) {
        create_table();
    }
    $hits = $tpl->javascript_parse_text("{hits}");
    $rulename = $tpl->javascript_parse_text("{rulename}");
    $new_rule = $tpl->javascript_parse_text("{new_rule}");
    $lang = $tpl->javascript_parse_text("{language}");
    $rule = $tpl->javascript_parse_text("{rule}");
    $title = $tpl->javascript_parse_text("{subject}");
    $new_template = $tpl->javascript_parse_text("{new_template}");
    $apply = $tpl->javascript_parse_text("{apply}");
    $online_help = $tpl->javascript_parse_text("{online_help}");
    $date = $tpl->javascript_parse_text("{zDate}");
    $replace = $tpl->_ENGINE_parse_body("{replace}");
    $sitename = $tpl->javascript_parse_text("{sitename}");
    $size = $tpl->javascript_parse_text("{size}");
    $sitename_explain = $tpl->javascript_parse_text("{artica_cache_rule_explain_sitename}");
    $t = time();
    $backToDefault = $tpl->javascript_parse_text("{backToDefault}");
    $ERROR_SQUID_REBUILD_TPLS = $tpl->javascript_parse_text("{ERROR_SQUID_REBUILD_TPLS}");
    $q = new mysql_squid_builder();
    $q = new mysql_squid_builder();
    $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT rulename,foldersize FROM artica_caches WHERE ID='{$_GET["ID"]}'", "artica_backup"));
    $enforce_rules = $tpl->javascript_parse_text("{enforce_rules}:{$ligne["rulename"]} (" . FormatBytes($ligne["foldersize"] / 1024) . ")");
    //if(!$users->CORP_LICENSE){
    //$error="<p class=text-error>".$tpl->_ENGINE_parse_body("{MOD_TEMPLATE_ERROR_LICENSE}")."</p>";
    //}
    $buttons = "\n\tbuttons : [\n\t{name: '{$new_rule}', bclass: 'add', onpress : NewRule{$t}},\n\t{name: '{$apply}', bclass: 'Reconf', onpress : Apply{$t}},\n\n\t],";
    $buttons = null;
    $html = "\n\t{$error}\n\t<table class='squid_enforce_foldersize' style='display: none' id='squid_enforce_foldersize' style='width:99%'></table>\n\n\t<script>\n\tvar mem{$t}='';\n\t\$(document).ready(function(){\n\t\$('#squid_enforce_foldersize').flexigrid({\n\turl: '{$page}?liste-rules=yes&ID={$_GET["ID"]}',\n\tdataType: 'json',\n\tcolModel : [\n\t{display: '{$sitename}', name : 'sitename', width : 629, sortable : false, align: 'left'},\n\t{display: '{$size}', name : 'foldersize', width : 184, sortable : true, align: 'right'},\n\n\t],\n\t{$buttons}\n\tsearchitems : [\n\t{display: '{$sitename}', name : 'sitename'},\n\t],\n\tsortname: 'sizebytes',\n\tsortorder: 'desc',\n\tusepager: true,\n\ttitle: '<span style=font-size:18px>{$enforce_rules}</span>',\n\tuseRp: true,\n\trp: 250,\n\tshowTableToggleBtn: false,\n\twidth: '99%',\n\theight: 400,\n\tsingleSelect: true\n\n});\n});\n\n\n\nvar xNewRule{$t}= function (obj) {\nvar tempvalue=obj.responseText;\nif(tempvalue.length>3){alert(tempvalue);}\n\$('#squid_enforce_foldersize').flexReload();\n}\n\nfunction NewRule{$t}(){\nvar rule=prompt('{$rulename} ?');\nif(!rule){return;}\nvar sitename=prompt('{$sitename_explain}');\nif(!sitename){return;}\nvar XHR = new XHRConnection();\nXHR.appendData('new-rule',encodeURIComponent(rule));\nXHR.appendData('sitename',encodeURIComponent(sitename));\nXHR.sendAndLoad('{$page}', 'POST',xNewRule{$t});\n}\n\nfunction Apply{$t}(){\nLoadjs('squid.artica-rules.progress.php');\n}\n\n</script>\n";
    echo $html;
}
Beispiel #22
0
function find_for_tags()
{
    $response = check_table_exist(strtolower($_GET['parameter']));
    if ($response == "FALSE") {
        $array = parse('https://www.mashape.com/explore' . switch_type($_GET['type']) . $_GET['parameter']);
        create_table(strtolower($_GET['parameter']), $array);
        echo json_encode($array);
    } else {
        $date = date("Y/m/d");
        $diff = get_count_days(strtolower($_GET['parameter']), $date);
        //  echo "diff".$diff;
        if ($diff > 6) {
            $array = parse('https://www.mashape.com/explore' . switch_type($_GET['type']) . $_GET['parameter']);
            $table = $_GET['parameter'];
            load_json_to_db($table, $array);
            echo json_encode($array);
        } else {
            $array = read_from_cache(strtolower($_GET['parameter']));
            echo json_encode($array);
        }
    }
}
Beispiel #23
0
function xmldb_local_upgrade($oldversion = 0)
{
    global $CFG, $THEME, $USER, $db;
    $result = true;
    if ($oldversion < 2007101901) {
        /// Create su_user table (additional attributes to user table)
        $table = new XMLDBTable('user');
        $field = new XMLDBField('su_isadvanced');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '1', false, false, false, false, null, null, 'screenreader');
        //        $table->addFieldInfo('id',XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, false, null, null, null);
        //        $table->addFieldInfo('user_id',XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, false, null, null, 'id');
        //        $table->addFieldInfo('isAdvanced',XMLDB_TYPE_INTEGER, '1', false, false, false, false, null, null, 'user_id');
        //        $table->addKeyInfo('primary',XMLDB_KEY_PRIMARY,array('id'));
        //        $table->addKeyInfo('fk_su_user_user',XMLDB_KEY_FOREIGN,array('user_id'),'user',array('id'));
        // Create the table
        $result = $result && add_field($table, $field);
    }
    if ($result && $oldversion < 2008031801) {
        /// Define table enrol_bank_requests to be created
        $table = new XMLDBTable('enrol_bank_requests');
        /// Adding fields to table enrol_bank_requests
        $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
        $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
        $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
        $table->addFieldInfo('varnum', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '4294967295');
        $table->addFieldInfo('requesttime', XMLDB_TYPE_DATETIME, null, null, null, null, null, null, null);
        /// Adding keys to table enrol_bank_requests
        $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
        $table->addKeyInfo('fk_enrol_bank_request_user', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
        $table->addKeyInfo('fk_enrol_bank_request_course', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
        /// Adding indexes to table enrol_bank_requests
        $table->addIndexInfo('ind_enrol_bank_requests_varnum', XMLDB_INDEX_UNIQUE, array('varnum'));
        /// Launch create table for enrol_bank_requests
        $result = $result && create_table($table);
    }
    return $result;
    return $result;
}
/**
 * Appends a row to the log table
 * @params
 *		$key	:string, a short description of the data to be stored
 * 		$data	:the data to be stored
 * @returns true on success, dies otherwise
 */
function log_this($key, $data = '')
{
    $key = mysql_escape_string($key);
    $data = mysql_escape_string($data);
    if (!table_exists(DB_TABLE_LOG)) {
        create_table(DB_TABLE_LOG, "id INT AUTO_INCREMENT, time INT, label TEXT, data TEXT, PRIMARY KEY (id)");
    } else {
        // nothing is kept older than 3 days
        $time = time() - 60 * 60 * 24 * 3;
        $query = "DELETE from " . DB_TABLE_LOG . " WHERE time<{$time}";
        $result = mysql_query($query);
        if (mysql_errno != 0) {
            die("MySQL error: " . mysql_errno());
        }
    }
    $query = "INSERT INTO " . DB_TABLE_LOG . "(time, label, data) VALUES ( " . time() . ", \"{$key}\", \"{$data}\")";
    $result = mysql_query($query);
    if (mysql_errno != 0) {
        die("MySQL error: " . mysql_errno());
    } else {
        return true;
    }
}
/**
 * ELIS(TM): Enterprise Learning Intelligence Suite
 * Copyright (C) 2008-2012 Remote Learner.net Inc http://www.remote-learner.net
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @package    elis
 * @subpackage php_reports
 * @author     Remote-Learner.net Inc
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @copyright  (C) 2008-2012 Remote Learner.net Inc http://www.remote-learner.net
 *
 */
function xmldb_block_php_report_upgrade($oldversion = 0)
{
    global $CFG, $THEME, $db;
    $result = true;
    if ($result && $oldversion < 2011040600) {
        /// Define table php_report_schedule to be created
        $table = new XMLDBTable('php_report_schedule');
        /// Adding fields to table php_report_schedule
        $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
        $table->addFieldInfo('report', XMLDB_TYPE_CHAR, '63', null, XMLDB_NOTNULL, null, null, null, null);
        $table->addFieldInfo('config', XMLDB_TYPE_TEXT, 'medium', null, XMLDB_NOTNULL, null, null, null, null);
        /// Adding keys to table php_report_schedule
        $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
        /// Adding indexes to table php_report_schedule
        $table->addIndexInfo('report_idx', XMLDB_INDEX_NOTUNIQUE, array('report'));
        /// Launch create table for php_report_schedule
        $result = $result && create_table($table);
        /// Define field userid to be added to php_report_schedule
        $table = new XMLDBTable('php_report_schedule');
        $field = new XMLDBField('userid');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'id');
        /// Launch add field userid
        $result = $result && add_field($table, $field);
        /// Define index userid_idx (not unique) to be added to php_report_schedule
        $table = new XMLDBTable('php_report_schedule');
        $index = new XMLDBIndex('userid_idx');
        $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('userid'));
        /// Launch add index userid_idx
        $result = $result && add_index($table, $index);
    }
    if ($result && $oldversion < 2011042900) {
        $query = "name " . sql_ilike() . " 'php_report%'";
        $result = $result && delete_records_select('user_preferences', $query);
    }
    return $result;
}
Beispiel #26
0
function xmldb_artefact_file_upgrade($oldversion = 0)
{
    $status = true;
    if ($oldversion < 2007010900) {
        $table = new XMLDBTable('artefact_file_files');
        $field = new XMLDBField('adminfiles');
        $field->setAttributes(XMLDB_TYPE_INTEGER, 1, false, true, false, null, null, 0);
        add_field($table, $field);
        set_field('artefact_file_files', 'adminfiles', 0);
        // Put all folders into artefact_file_files
        $folders = get_column_sql("\n            SELECT a.id\n            FROM {artefact} a\n            LEFT OUTER JOIN {artefact_file_files} f ON a.id = f.artefact\n            WHERE a.artefacttype = 'folder' AND f.artefact IS NULL");
        if ($folders) {
            foreach ($folders as $folderid) {
                $data = (object) array('artefact' => $folderid, 'adminfiles' => 0);
                insert_record('artefact_file_files', $data);
            }
        }
    }
    if ($oldversion < 2007011800) {
        // Make sure the default quota is set
        set_config_plugin('artefact', 'file', 'defaultquota', 10485760);
    }
    if ($oldversion < 2007011801) {
        // Create image table
        $table = new XMLDBTable('artefact_file_image');
        $table->addFieldInfo('artefact', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL);
        $table->addFieldInfo('width', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL);
        $table->addFieldInfo('height', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null);
        $table->addKeyInfo('artefactfk', XMLDB_KEY_FOREIGN, array('artefact'), 'artefact', array('id'));
        $status = $status && create_table($table);
        $images = get_column('artefact', 'id', 'artefacttype', 'image');
        log_debug(count($images));
        require_once get_config('docroot') . 'artefact/lib.php';
        foreach ($images as $imageid) {
            $image = artefact_instance_from_id($imageid);
            $path = $image->get_path();
            $image->set('dirty', false);
            $data = new StdClass();
            $data->artefact = $imageid;
            if (file_exists($path)) {
                list($data->width, $data->height) = getimagesize($path);
            }
            if (empty($data->width) || empty($data->height)) {
                $data->width = 0;
                $data->height = 0;
            }
            insert_record('artefact_file_image', $data);
        }
    }
    if ($oldversion < 2007013100) {
        // Add new tables for file/mime types
        $table = new XMLDBTable('artefact_file_file_types');
        $table->addFieldInfo('description', XMLDB_TYPE_TEXT, 128, null, XMLDB_NOTNULL);
        $table->addFieldInfo('enabled', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 1);
        $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('description'));
        create_table($table);
        $table = new XMLDBTable('artefact_file_mime_types');
        $table->addFieldInfo('mimetype', XMLDB_TYPE_TEXT, 128, null, XMLDB_NOTNULL);
        $table->addFieldInfo('description', XMLDB_TYPE_TEXT, 128, null, XMLDB_NOTNULL);
        $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('mimetype'));
        $table->addKeyInfo('descriptionfk', XMLDB_KEY_FOREIGN, array('description'), 'artefact_file_file_types', array('description'));
        create_table($table);
        safe_require('artefact', 'file');
        PluginArtefactFile::resync_filetype_list();
    }
    if ($oldversion < 2007021400) {
        $table = new XMLDBTable('artefact_file_files');
        $field = new XMLDBField('oldextension');
        $field->setAttributes(XMLDB_TYPE_TEXT);
        add_field($table, $field);
    }
    if ($oldversion < 2007042500) {
        // migrate everything we had to change to  make mysql happy
        execute_sql("ALTER TABLE {artefact_file_file_types} ALTER COLUMN description TYPE varchar(32)");
        execute_sql("ALTER TABLE {artefact_file_mime_types} ALTER COLUMN mimetype TYPE varchar(128)");
        execute_sql("ALTER TABLE {artefact_file_mime_types} ALTER COLUMN description TYPE varchar(32)");
    }
    if ($oldversion < 2008091100) {
        $table = new XMLDBTable('artefact_file_files');
        $field = new XMLDBField('fileid');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null);
        add_field($table, $field);
        execute_sql("UPDATE {artefact_file_files} SET fileid = artefact WHERE NOT size IS NULL");
    }
    if ($oldversion < 2008101602) {
        $table = new XMLDBTable('artefact_file_files');
        $field = new XMLDBField('filetype');
        $field->setAttributes(XMLDB_TYPE_TEXT);
        add_field($table, $field);
        // Guess mime type for existing files
        $fileartefacts = get_records_sql_array('
            SELECT
                a.artefacttype, f.artefact, f.oldextension, f.fileid
            FROM
                {artefact} a,
                {artefact_file_files} f
            WHERE
                a.id = f.artefact
        ', array());
        require_once get_config('libroot') . 'file.php';
        if ($fileartefacts) {
            foreach ($fileartefacts as $a) {
                $type = null;
                if ($a->artefacttype == 'image') {
                    $size = getimagesize(get_config('dataroot') . 'artefact/file/originals/' . $a->fileid % 256 . '/' . $a->fileid);
                    $type = $size['mime'];
                } else {
                    if ($a->artefacttype == 'profileicon') {
                        $size = getimagesize(get_config('dataroot') . 'artefact/file/profileicons/originals/' . $a->fileid % 256 . '/' . $a->fileid);
                        $type = $size['mime'];
                    } else {
                        if ($a->artefacttype == 'file') {
                            $type = get_mime_type(get_config('dataroot') . 'artefact/file/originals/' . $a->fileid % 256 . '/' . $a->fileid);
                        }
                    }
                }
                if ($type) {
                    set_field('artefact_file_files', 'filetype', $type, 'artefact', $a->artefact);
                }
            }
        }
        delete_records('config', 'field', 'pathtofile');
    }
    if ($oldversion < 2008101701) {
        if ($data = get_config_plugin('blocktype', 'internalmedia', 'enabledtypes')) {
            $olddata = unserialize($data);
            $newdata = array();
            foreach ($olddata as $d) {
                if ($d == 'mov') {
                    $newdata[] = 'quicktime';
                } else {
                    if ($d == 'mp4') {
                        $newdata[] = 'mp4_video';
                    } else {
                        if ($d != 'mpg') {
                            $newdata[] = $d;
                        }
                    }
                }
            }
            set_config_plugin('blocktype', 'internalmedia', 'enabledtypes', serialize($newdata));
        }
    }
    if ($oldversion < 2009021200) {
        $table = new XMLDBTable('artefact_file_mime_types');
        $key = new XMLDBKey('artefilemimetype_des_fk');
        $key->setAttributes(XMLDB_KEY_FOREIGN, array('description'), 'artefact_file_file_types', array('description'));
        drop_key($table, $key);
        $table = new XMLDBTable('artefact_file_file_types');
        drop_table($table);
        PluginArtefactFile::resync_filetype_list();
    }
    if ($oldversion < 2009021301) {
        // IE has been uploading jpegs with the image/pjpeg mimetype,
        // which is not recognised as an image by the download script.
        // Fix all existing jpegs in the db:
        set_field('artefact_file_files', 'filetype', 'image/jpeg', 'filetype', 'image/pjpeg');
        // This won't happen again because we now read the contents of the
        // uploaded file to detect image artefacts, and overwrite the mime
        // type declared by the browser if we see an image.
    }
    if ($oldversion < 2009033000) {
        if (!get_record('artefact_config', 'plugin', 'file', 'field', 'uploadagreement')) {
            insert_record('artefact_config', (object) array('plugin' => 'file', 'field' => 'uploadagreement', 'value' => 1));
            insert_record('artefact_config', (object) array('plugin' => 'file', 'field' => 'usecustomagreement', 'value' => 1));
        }
    }
    return $status;
}
Beispiel #27
0
    return true;
}
if (!($link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))) {
    printf("[001] Cannot connect - [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
}
/* create new table and select from it */
$expected = create_table($link, 'FLOAT', -10000, 10000, $engine, 90);
foreach ($expected as $k => $v) {
    $expected[$k] = number_format(round($v), 0, '.', ',');
}
test_format($link, 'FORMAT(col1, 0)', 'test_bug42378_table_1', NULL, array(), 100);
$expected = create_table($link, 'FLOAT', -10000, 10000, $engine, 110);
foreach ($expected as $k => $v) {
    $expected[$k] = number_format(round($v), 0, '.', ',');
}
test_format($link, 'id AS order_by_col, FORMAT(col1, 0)', 'test_bug42378_table_1', 'id', $expected, 120);
$expected = create_table($link, 'FLOAT UNSIGNED', 0, 10000, $engine, 130);
foreach ($expected as $k => $v) {
    $expected[$k] = number_format(round($v), 0, '.', ',');
}
test_format($link, 'id AS order_by_col, FORMAT(col1, 0)', 'test_bug42378_table_1', 'id', $expected, 140);
$expected = create_table($link, 'DECIMAL(5,0)', -1000, 1000, $engine, 150);
foreach ($expected as $k => $v) {
    $expected[$k] = number_format(round($v), 0, '.', ',');
}
test_format($link, 'id AS order_by_col, FORMAT(col1, 0)', 'test_bug42378_table_1', 'id', $expected, 160);
mysqli_close($link);
print "done!";
error_reporting(0);
$test_table_name = 'test_bug42378_table_1';
require_once "clean_table.inc";
function xmldb_oublog_upgrade($oldversion = 0)
{
    global $CFG, $THEME, $db;
    $result = true;
    if ($result && $oldversion < 2008022600) {
        /// Define field views to be added to oublog_instances
        $table = new XMLDBTable('oublog_instances');
        $field = new XMLDBField('views');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'accesstoken');
        /// Launch add field views
        $result = $result && add_field($table, $field);
        $table = new XMLDBTable('oublog');
        $field = new XMLDBField('views');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'global');
        /// Launch add field views
        $result = $result && add_field($table, $field);
    }
    if ($result && $oldversion < 2008022700) {
        /// Define field oublogid to be added to oublog_links
        $table = new XMLDBTable('oublog_links');
        $field = new XMLDBField('oublogid');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'id');
        /// Launch add field oublogid
        $result = $result && add_field($table, $field);
        /// Define key oublog_links_oublog_fk (foreign) to be added to oublog_links
        $table = new XMLDBTable('oublog_links');
        $key = new XMLDBKey('oublog_links_oublog_fk');
        $key->setAttributes(XMLDB_KEY_FOREIGN, array('oublogid'), 'oublog', array('id'));
        /// Launch add key oublog_links_oublog_fk
        $result = $result && add_key($table, $key);
        /// Changing nullability of field oubloginstancesid on table oublog_links to null
        $table = new XMLDBTable('oublog_links');
        $field = new XMLDBField('oubloginstancesid');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'oublogid');
        /// Launch change of nullability for field oubloginstancesid
        $result = $result && change_field_notnull($table, $field);
    }
    if ($result && $oldversion < 2008022701) {
        /// Define field sortorder to be added to oublog_links
        $table = new XMLDBTable('oublog_links');
        $field = new XMLDBField('sortorder');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'url');
        /// Launch add field sortorder
        $result = $result && add_field($table, $field);
    }
    if ($result && $oldversion < 2008030704) {
        /// Add search data
        require_once dirname(__FILE__) . '/../locallib.php';
        require_once dirname(__FILE__) . '/../lib.php';
        if (oublog_search_installed()) {
            global $db;
            $olddebug = $db->debug;
            $db->debug = false;
            print '<ul>';
            oublog_ousearch_update_all(true);
            print '</ul>';
            $db->debug = $olddebug;
        }
    }
    if ($result && $oldversion < 2008030707) {
        /// Define field lasteditedby to be added to oublog_posts
        $table = new XMLDBTable('oublog_posts');
        $field = new XMLDBField('lasteditedby');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'visibility');
        /// Launch add field lasteditedby
        $result = $result && add_field($table, $field);
        /// Transfer edit data to lasteditedby
        $result = $result && execute_sql("\r\nUPDATE {$CFG->prefix}oublog_posts SET lasteditedby=(\r\n    SELECT userid FROM {$CFG->prefix}oublog_edits WHERE {$CFG->prefix}oublog_posts.id=postid ORDER BY id DESC LIMIT 1 \r\n) WHERE editsummary IS NOT NULL\r\n        ");
        /// Define field editsummary to be dropped from oublog_posts
        $table = new XMLDBTable('oublog_posts');
        $field = new XMLDBField('editsummary');
        /// Launch drop field editsummary
        $result = $result && drop_field($table, $field);
    }
    if ($result && $oldversion < 2008073000) {
        /// Define field completionposts to be added to oublog
        $table = new XMLDBTable('oublog');
        $field = new XMLDBField('completionposts');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '9', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'views');
        /// Launch add field completionposts
        $result = $result && add_field($table, $field);
        /// Define field completioncomments to be added to oublog
        $field = new XMLDBField('completioncomments');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '9', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'completionposts');
        /// Launch add field completioncomments
        $result = $result && add_field($table, $field);
    }
    if ($result && $oldversion < 2008121100) {
        // remove oublog:view from legacy:user roles
        $roles = get_roles_with_capability('moodle/legacy:user', CAP_ALLOW);
        foreach ($roles as $role) {
            $result = $result && unassign_capability('mod/oublog:view', $role->id);
        }
    }
    if ($result && $oldversion < 2009012600) {
        // Remove oublog:post and oublog:comment from legacy:user roles (if present)
        $roles = get_roles_with_capability('moodle/legacy:user', CAP_ALLOW);
        // Also from default user role if not already included
        if (!array_key_exists($CFG->defaultuserroleid, $roles)) {
            $roles[] = get_record('role', 'id', $CFG->defaultuserroleid);
        }
        print '<p><strong>Warning</strong>: The OU blog system capabilities 
            have changed (again) in order to fix bugs and clarify access control.
            The system will automatically remove the capabilities 
            <tt>mod/oublog:view</tt>, <tt>mod/oublog:post</tt>, and
            <tt>mod/oublog:comment</tt> from the following role(s):</p><ul>';
        foreach ($roles as $role) {
            print '<li>' . htmlspecialchars($role->name) . '</li>';
            $result = $result && unassign_capability('mod/oublog:view', $role->id);
            $result = $result && unassign_capability('mod/oublog:post', $role->id);
            $result = $result && unassign_capability('mod/oublog:comment', $role->id);
        }
        print '</ul><p>On a default Moodle installation this is the correct 
            behaviour. Personal blog access is now controlled via the 
            <tt>mod/oublog:viewpersonal</tt> and 
            <tt>mod/oublog:contributepersonal</tt>
            capabilities. These capabilities have been added to the 
            authenticated user role and any equivalent roles.</p>
            <p>If in doubt, please examine your role configuration with regard
            to these <tt>mod/oublog</tt> capabilities.</p>';
    }
    if ($result && $oldversion < 2010031200) {
        /// Define field completionposts to be added to oublog
        $table = new XMLDBTable('oublog');
        $field = new XMLDBField('individual');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'completioncomments');
        /// Launch add field completioncomments
        $result = $result && add_field($table, $field);
    }
    if ($result && $oldversion < 2010062400) {
        /// Define table oublog_comments_moderated to be created
        $table = new XMLDBTable('oublog_comments_moderated');
        /// Adding fields to table oublog_comments_moderated
        $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
        $table->addFieldInfo('postid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
        $table->addFieldInfo('title', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
        $table->addFieldInfo('message', XMLDB_TYPE_TEXT, 'medium', null, XMLDB_NOTNULL, null, null, null, null);
        $table->addFieldInfo('timeposted', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
        $table->addFieldInfo('authorname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
        $table->addFieldInfo('ipaddress', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
        $table->addFieldInfo('approval', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
        $table->addFieldInfo('timeset', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
        $table->addFieldInfo('secretkey', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
        /// Adding keys to table oublog_comments_moderated
        $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
        $table->addKeyInfo('postid', XMLDB_KEY_FOREIGN, array('postid'), 'oublog_posts', array('id'));
        /// Adding indexes to table oublog_comments_moderated
        $table->addIndexInfo('ipaddress', XMLDB_INDEX_NOTUNIQUE, array('ipaddress'));
        /// Launch create table for oublog_comments_moderated
        $result = $result && create_table($table);
        /// Changing nullability of field userid on table oublog_comments to null
        $table = new XMLDBTable('oublog_comments');
        $field = new XMLDBField('userid');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'postid');
        /// Launch change of nullability for field userid
        $result = $result && change_field_notnull($table, $field);
        /// Define field authorname to be added to oublog_comments
        $field = new XMLDBField('authorname');
        $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null, 'timedeleted');
        /// Launch add field authorname
        $result = $result && add_field($table, $field);
        /// Define field authorip to be added to oublog_comments
        $field = new XMLDBField('authorip');
        $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null, 'authorname');
        /// Launch add field authorip
        $result = $result && add_field($table, $field);
        /// Define field timeapproved to be added to oublog_comments
        $field = new XMLDBField('timeapproved');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'authorip');
        /// Launch add field timeapproved
        $result = $result && add_field($table, $field);
    }
    if ($result && $oldversion < 2010062500) {
        // Change the 'allow comments' value to 2 on global blog, if it is
        // currently set to 1
        $result = $result && set_field('oublog', 'allowcomments', 2, 'global', 1, 'allowcomments', 1);
    }
    if ($result && $oldversion < 2010063000) {
        /// Define index ipaddress (not unique) to be dropped form oublog_comments_moderated
        $table = new XMLDBTable('oublog_comments_moderated');
        $index = new XMLDBIndex('ipaddress');
        $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('ipaddress'));
        /// Launch drop index authorip
        $result = $result && drop_index($table, $index);
        /// Rename field ipaddress on table oublog_comments_moderated to authorip
        $field = new XMLDBField('ipaddress');
        $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null, 'authorname');
        /// Launch rename field ipaddress
        $result = $result && rename_field($table, $field, 'authorip');
        /// Define index authorip (not unique) to be added to oublog_comments_moderated
        $table = new XMLDBTable('oublog_comments_moderated');
        $index = new XMLDBIndex('authorip');
        $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('authorip'));
        /// Launch add index authorip
        $result = $result && add_index($table, $index);
    }
    if ($result && $oldversion < 2010070101) {
        // Make cron start working - in some servers I found there was
        // 9999999999 in the lastcron field which caused it never to run; not
        // very helpful
        $result = $result && set_field('modules', 'lastcron', 1, 'name', 'oublog');
    }
    return $result;
}
Beispiel #29
0
             $PHORUM['DatabaseName'] = $dbName;
             $PHORUM['DatabaseUser'] = $dbUser;
             $PHORUM['DatabasePassword'] = $dbPass;
             writefile();
             echo "Database settings OK!<br />\n";
             if ($upgrade) {
                 echo "Upgrading tables...<br />";
                 if ($dbType == "mysql") {
                     include "{$admindir}/upgrade.php";
                 } else {
                     include "{$admindir}/upgrade_pg.php";
                 }
                 writefile("all");
             } else {
                 echo "Creating initial tables...";
                 if (($err = create_table($DB, "forums", $PHORUM["main_table"])) || ($err = create_table($DB, "auth", $PHORUM["main_table"])) || ($err = create_table($DB, "moderators", $PHORUM["main_table"]))) {
                     $err = "Could not create tables.  Server said: {$err}";
                 } else {
                     echo "tables created.<br />\n";
                 }
             }
         }
     }
     break;
 case 3:
     if (empty($AdminUser) || empty($AdminPass)) {
         $err = "Please fill in all fields";
     } elseif ($AdminPass != $AdminPass2) {
         $err = "Passwords do not match";
     } else {
         $id = $DB->nextid($PHORUM["auth_table"]);
 function configure_table($id, $rebuild = false, $returl = '')
 {
     global $_CAMILA;
     if ($this->interactive) {
         $this->db = $_CAMILA['db'];
     }
     if ($_REQUEST['camila_phpform_sent'] == 1 && !isset($_REQUEST['camila_worktable_op'])) {
         $record = array();
         $record['order_field'] = $_REQUEST['camila_order_field'];
         $record['order_dir'] = $_REQUEST['camila_order_dir'];
         $record['canupdate'] = $_REQUEST['camila_canupdate'];
         $record['caninsert'] = $_REQUEST['camila_caninsert'];
         $record['candelete'] = $_REQUEST['camila_candelete'];
         if ($_REQUEST['camila_short_title'] != '') {
             $record['short_title'] = $_REQUEST['camila_short_title'];
         }
         if ($_REQUEST['camila_full_title'] != '') {
             $record['full_title'] = $_REQUEST['camila_full_title'];
         }
         $updateSQL = $this->db->AutoExecute(CAMILA_TABLE_WORKT, $record, 'UPDATE', 'id=' . $this->db->qstr($id));
         if (!$updateSQL) {
             camila_information_text(camila_get_translation('camila.worktable.db.error'));
         }
     }
     $resultTable = $this->db->Execute('select * from ' . CAMILA_TABLE_WORKT . ' where id=' . $this->db->qstr($id));
     if ($resultTable === false) {
         camila_error_page(camila_get_translation('camila.sqlerror') . ' ' . $this->db->ErrorMsg());
     }
     $result = $this->db->Execute('select count(*) as c from ' . CAMILA_TABLE_WORKC . ' where (wt_id=' . $this->db->qstr($id) . ' and applied_to_database = ' . $this->db->qstr('y') . ' and is_deleted<>' . $this->db->qstr('y') . ')');
     if ($result === false) {
         camila_error_page(camila_get_translation('camila.sqlerror') . ' ' . $this->db->ErrorMsg());
     }
     $colsApplied = intval($result->fields['c']);
     $result = $this->db->Execute('select count(*) as c from ' . CAMILA_TABLE_WORKC . ' where (wt_id=' . $this->db->qstr($id) . ' and applied_to_database = ' . $this->db->qstr('n') . ' and is_deleted<>' . $this->db->qstr('y') . ')');
     if ($result === false) {
         camila_error_page(camila_get_translation('camila.sqlerror') . ' ' . $this->db->ErrorMsg());
     }
     $colsToApply = intval($result->fields['c']);
     //if ($colsToApply > 0 || $rebuild) {
     require_once CAMILA_DIR . 'db/schema.inc.php';
     $schema = "<?xml version=\"1.0\"?>\n";
     $schema .= "<schema version=\"0.2\">\n";
     $schema .= "<table name=\"" . CAMILA_TABLE_WORKP . "{$id}\">\n";
     $schema .= "<field name=\"id\" type=\"I\">\n";
     $schema .= "<KEY/>\n";
     $schema .= "<AUTOINCREMENT/>\n";
     $schema .= "</field>\n";
     $schema .= "<field name=\"created\" type=\"T\"/>\n";
     $schema .= "<field name=\"created_by\" type=\"C\" size=\"50\"/>\n";
     $schema .= "<field name=\"created_by_name\" type=\"C\" size=\"50\"/>\n";
     $schema .= "<field name=\"created_by_surname\" type=\"C\" size=\"50\"/>\n";
     $schema .= "<field name=\"created_src\" type=\"C\" size=\"30\"/>\n";
     $schema .= "<field name=\"last_upd\" type=\"T\"/>\n";
     $schema .= "<field name=\"last_upd_by\" type=\"C\" size=\"50\"/>\n";
     $schema .= "<field name=\"last_upd_by_name\" type=\"C\" size=\"50\"/>\n";
     $schema .= "<field name=\"last_upd_by_surname\" type=\"C\" size=\"50\"/>\n";
     $schema .= "<field name=\"last_upd_src\" type=\"C\" size=\"30\"/>\n";
     $schema .= "<field name=\"grp\" type=\"C\" size=\"20\"/>\n";
     $schema .= "<field name=\"mod_num\" type=\"I\"/>\n";
     $schema .= "<field name=\"is_deleted\" type=\"C\" size=\"1\"/>\n";
     $schema .= "<field name=\"cf_bool_is_selected\" type=\"C\" size=\"1\"><DEFAULT value=\"n\"/>\r\n</field>\n";
     $schema .= "<field name=\"cf_bool_is_special\" type=\"C\" size=\"1\"><DEFAULT value=\"n\"/>\r\n</field>\n";
     //if ($this->db->databaseType == 'sqlite' || $rebuild)
     $result = $this->db->Execute('select * from ' . CAMILA_TABLE_WORKC . ' where wt_id=' . $this->db->qstr($id) . ' order by sequence');
     //else
     //    $result = $this->db->Execute('select * from ' . CAMILA_TABLE_WORKC . ' where wt_id='.$this->db->qstr($id) . ' and applied_to_database = ' . $this->db->qstr('n') . ' order by sequence');
     if ($result === false) {
         camila_error_page(camila_get_translation('camila.sqlerror') . ' ' . $this->db->ErrorMsg());
     }
     while (!$result->EOF) {
         $schema .= $this->get_xml_schema_tag($result->fields);
         $result->MoveNext();
     }
     $schema .= "</table>\n";
     $schema .= "</schema>\n";
     $filename = CAMILA_TMP_DIR . '/' . CAMILA_TABLE_WORKP . $id . '.xml';
     $f = fopen($filename, 'w');
     fwrite($f, $schema);
     fclose($f);
     if (!$rebuild && $colsApplied > 0 && $this->db->databaseType == 'sqlite') {
         $sql0 = sprintf($this->db->_dropSeqSQL, 'temp_' . CAMILA_TABLE_WORKP . $id);
         $result = $this->db->Execute($sql0);
         //if ($result === false)
         //    camila_error_page(camila_get_translation('camila.sqlerror') . ' ' . $this->db->ErrorMsg());
         $sql1 = 'create table temp_' . CAMILA_TABLE_WORKP . $id . ' as select * from ' . CAMILA_TABLE_WORKP . $id;
         $result = $this->db->Execute($sql1);
         if ($result === false) {
             camila_error_page(camila_get_translation('camila.sqlerror') . ' ' . $this->db->ErrorMsg());
         }
     }
     $result = create_table($filename, '', $this->db, $colsApplied > 0 && $this->db->databaseType != 'sqlite' && !$rebuild ? false : true);
     if ($result['result'] == 2) {
         $record = array();
         $record['applied_to_database'] = 'y';
         $updateSQL = $this->db->AutoExecute(CAMILA_TABLE_WORKC, $record, 'UPDATE', 'wt_id=' . $this->db->qstr($id));
         if (!$updateSQL) {
             camila_information_text(camila_get_translation('camila.worktable.db.error'));
         }
     } else {
         echo $file . ' - KO - ' . $result['sql'];
     }
     if (!$rebuild && $colsApplied > 0 && $this->db->databaseType == 'sqlite') {
         $sql = 'pragma table_info (temp_' . CAMILA_TABLE_WORKP . $id . ')';
         $result = $this->db->Execute($sql);
         if ($result === false) {
             camila_error_page(camila_get_translation('camila.sqlerror') . ' ' . $this->db->ErrorMsg());
         }
         $cols = '';
         while (!$result->EOF) {
             $cols .= ',' . $result->fields['name'];
             $result->MoveNext();
         }
         $cols = substr($cols, 1);
         $sql2 = 'insert into ' . CAMILA_TABLE_WORKP . $id . '(' . $cols . ') select ' . $cols . ' from temp_' . CAMILA_TABLE_WORKP . $id;
         $result = $this->db->Execute($sql2);
         if ($result === false) {
             camila_error_page(camila_get_translation('camila.sqlerror') . ' ' . $this->db->ErrorMsg());
         }
         $sql3 = sprintf($this->db->_dropSeqSQL, 'temp_' . CAMILA_TABLE_WORKP . $id);
         $result = $this->db->Execute($sql3);
         if ($result === false) {
             camila_error_page(camila_get_translation('camila.sqlerror') . ' ' . $this->db->ErrorMsg());
         }
     }
     //}
     $success3 = $this->create_script_from_template($id);
     $resultTemp = $this->db->Execute('select id from ' . CAMILA_TABLE_WORKT . ' where id<>' . $this->db->qstr($id));
     if ($resultTemp === false) {
         camila_error_page(camila_get_translation('camila.sqlerror') . ' ' . $this->db->ErrorMsg());
     }
     while (!$resultTemp->EOF) {
         $successTemp = $this->create_script_from_template($resultTemp->fields['id']);
         $resultTemp->MoveNext();
     }
     $record = array();
     $record['short_title'] = $resultTable->fields['short_title'];
     $record['full_title'] = $resultTable->fields['full_title'];
     $success4 = true;
     $updateSQL = $this->db->AutoExecute(CAMILA_TABLE_PLANG, $record, 'UPDATE', 'page_url=' . $this->db->qstr($resultTable->fields['scriptname']) . ' and lang=' . $this->db->qstr($_CAMILA['lang']));
     if (!$updateSQL) {
         camila_information_text(camila_get_translation('camila.worktable.db.error'));
         $success4 = false;
     }
     require_once CAMILA_DIR . 'datagrid/form.class.php';
     require_once CAMILA_DIR . 'datagrid/elements/form/hidden.php';
     if ($this->interactive) {
         $myText = new CHAW_text(camila_get_translation('camila.wizard.configurationapplied'));
         $_CAMILA['page']->add_text($myText);
         if ($returl != '') {
             $form3 = new phpform('camila', $returl, HAW_METHOD_GET);
         } elseif ($colsApplied > 0) {
             $form3 = new phpform('camila', 'cf_worktable_admin.php', HAW_METHOD_GET);
         } else {
             $form3 = new phpform('camila', 'cf_worktable_wizard_step4.php', HAW_METHOD_GET);
         }
         $form3->submitbutton = camila_get_translation('camila.wizard.next');
         $form3->drawrules = false;
         new form_hidden($form3, 'custom', $id);
         $form3->process();
         $form3->draw();
     }
 }