Example #1
0
function query_registered_users()
{
    // Initialize the return code.
    $b_rc = false;
    // Initialize array to store query results in.
    $registered_users = array();
    // Open connection to the database.
    list($b_rc, $db_handle) = connect_to_database();
    // If return code is true proceed with data query.
    if ($b_rc) {
        // Set MySQL table to use.
        $sql_table = "data_submission";
        // Create MySQL query to request all registered user entries in descending
        // order by timestamp.
        $sql_query = "SELECT * FROM {$sql_table} ORDER BY timestamp DESC";
        // Perform database query.
        $result = mysql_query($sql_query, $db_handle);
        // Validate return code from query.
        check_result($result);
        // Fetch each registered user's information from the query results
        // and add it to an array that can be returned to the caller.
        while ($row = mysql_fetch_row($result)) {
            //echo "timestamp = $row[8]<br>";
            // Add user's information to array.
            $registered_users[] = $row;
        }
        // Free the query results.
        mysql_free_result($result);
    }
    // Return array consisting of status boolean and query data.
    return array($b_rc, $registered_users);
}
Example #2
0
/**
* Create the database and the tables in it
* - Requires an external file with sql commands
* @param none
*/
function doCreate()
{
    global $db;
    global $conf;
    $announcements = DBEngine::get_table('announcements');
    $login = DBEngine::get_table('login');
    $reservations = DBEngine::get_table('reservations');
    $resources = DBEngine::get_table('resources');
    $permission = DBEngine::get_table('permission');
    $schedule_permission = DBEngine::get_table('schedule_permission');
    $schedules = DBEngine::get_table('schedules');
    $reservation_users = DBEngine::get_table('reservation_users');
    $anonymous_users = DBEngine::get_table('anonymous_users');
    $additional_resources = DBEngine::get_table('additional_resources');
    $reservation_resources = DBEngine::get_table('reservation_resources');
    $mutex = DBEngine::get_table('mutex');
    $groups = DBEngine::get_table('groups');
    $user_groups = DBEngine::get_table('user_groups');
    $reminders = DBEngine::get_table('reminders');
    $sqls = array(array("create database {$conf['db']['dbName']}", "Creating database"), array("use {$conf['db']['dbName']}", "Selecting database"), array("CREATE TABLE {$announcements} (\r\n\t\t\t\t\t\t\t\tannouncementid CHAR(16) NOT NULL PRIMARY KEY,\r\n\t\t\t\t\t\t\t\tannouncement VARCHAR(255) NOT NULL DEFAULT '',\r\n\t\t\t\t\t\t\t\tnumber SMALLINT NOT NULL DEFAULT '0',\r\n\t\t\t\t\t\t\t\tstart_datetime INTEGER,\r\n\t\t\t\t\t\t\t\tend_datetime INTEGER\r\n\t\t\t\t\t\t\t)", "Creating announcement table"), array("CREATE INDEX announcements_startdatetime ON {$announcements}(start_datetime)", 'Creating index'), array("CREATE INDEX announcements_enddatetime ON {$announcements}(end_datetime)", 'Creating index'), array("CREATE TABLE {$login} (\r\n\t\t\t\t\t\t\t  memberid CHAR(16) NOT NULL PRIMARY KEY,\r\n\t\t\t\t\t\t\t  email VARCHAR(75) NOT NULL,\r\n\t\t\t\t\t\t\t  password CHAR(32) NOT NULL,\r\n\t\t\t\t\t\t\t  fname VARCHAR(30) NOT NULL,\r\n\t\t\t\t\t\t\t  lname VARCHAR(30) NOT NULL,\r\n\t\t\t\t\t\t\t  phone VARCHAR(16) NOT NULL,\r\n\t\t\t\t\t\t\t  institution VARCHAR(255),\r\n\t\t\t\t\t\t\t  position VARCHAR(100),\r\n\t\t\t\t\t\t\t  e_add CHAR(1) NOT NULL DEFAULT 'y',\r\n\t\t\t\t\t\t\t  e_mod CHAR(1) NOT NULL DEFAULT 'y',\r\n\t\t\t\t\t\t\t  e_del CHAR(1) NOT NULL DEFAULT 'y',\r\n\t\t\t\t\t\t\t  e_app CHAR(1) NOT NULL DEFAULT 'y',\r\n\t\t\t\t\t\t\t  e_html CHAR(1) NOT NULL DEFAULT 'y',\r\n\t\t\t\t\t\t\t  logon_name VARCHAR(30),\r\n\t\t\t\t\t\t\t  is_admin SMALLINT DEFAULT 0,\r\n\t\t\t\t\t\t\t  lang VARCHAR(5),\r\n\t\t\t\t\t\t\t  timezone FLOAT NOT NULL DEFAULT 0\r\n\t\t\t\t\t\t\t  )", 'Creating login table'), array("CREATE INDEX login_email ON {$login} (email)", 'Creating index'), array("CREATE INDEX login_password ON {$login} (password)", 'Creating index'), array("CREATE INDEX login_logonname ON {$login} (logon_name)", 'Creating index'), array("CREATE TABLE {$reservations} (\r\n\t\t\t\t\t\t\t  resid CHAR(16) NOT NULL PRIMARY KEY,\r\n\t\t\t\t\t\t\t  machid CHAR(16) NOT NULL,\r\n\t\t\t\t\t\t\t  scheduleid CHAR(16) NOT NULL,\r\n\t\t\t\t\t\t\t  start_date INT NOT NULL DEFAULT 0,\r\n\t\t\t\t\t\t\t  end_date INT NOT NULL DEFAULT 0,\r\n\t\t\t\t\t\t\t  starttime INTEGER NOT NULL,\r\n\t\t\t\t\t\t\t  endtime INTEGER NOT NULL,\r\n\t\t\t\t\t\t\t  created INTEGER NOT NULL,\r\n\t\t\t\t\t\t\t  modified INTEGER,\r\n\t\t\t\t\t\t\t  parentid CHAR(16),\r\n\t\t\t\t\t\t\t  is_blackout SMALLINT NOT NULL DEFAULT 0,\r\n\t\t\t\t\t\t\t  is_pending SMALLINT NOT NULL DEFAULT 0,\r\n\t\t\t\t\t\t\t  summary TEXT,\r\n\t\t\t\t\t\t\t  allow_participation SMALLINT NOT NULL DEFAULT 0,\r\n\t\t\t\t\t\t\t  allow_anon_participation SMALLINT NOT NULL DEFAULT 0\r\n\t\t\t\t\t\t\t  )", 'Creating reservations table'), array("CREATE INDEX res_machid ON {$reservations} (machid)", 'Creating index'), array("CREATE INDEX res_scheduleid ON {$reservations} (scheduleid)", 'Creating index'), array("CREATE INDEX reservations_startdate ON {$reservations} (start_date)", 'Creating index'), array("CREATE INDEX reservations_enddate ON {$reservations} (end_date)", 'Creating index'), array("CREATE INDEX res_startTime ON {$reservations} (starttime)", 'Creating index'), array("CREATE INDEX res_endTime ON {$reservations} (endtime)", 'Creating index'), array("CREATE INDEX res_created ON {$reservations} (created)", 'Creating index'), array("CREATE INDEX res_modified ON {$reservations} (modified)", 'Creating index'), array("CREATE INDEX res_parentid ON {$reservations} (parentid)", 'Creating index'), array("CREATE INDEX res_isblackout ON {$reservations} (is_blackout)", 'Creating index'), array("CREATE INDEX reservations_pending ON {$reservations} (is_pending)", 'Creating index'), array("CREATE TABLE {$resources} (\r\n\t\t\t\t\t\t\t  machid CHAR(16) NOT NULL PRIMARY KEY,\r\n\t\t\t\t\t\t\t  scheduleid CHAR(16) NOT NULL,\r\n\t\t\t\t\t\t\t  name VARCHAR(75) NOT NULL,\r\n\t\t\t\t\t\t\t  location VARCHAR(250),\r\n\t\t\t\t\t\t\t  rphone VARCHAR(16),\r\n\t\t\t\t\t\t\t  notes TEXT,\r\n\t\t\t\t\t\t\t  status CHAR(1) NOT NULL DEFAULT 'a',\r\n\t\t\t\t\t\t\t  minres INTEGER NOT NULL,\r\n\t\t\t\t\t\t\t  maxres INTEGER NOT NULL,\r\n\t\t\t\t\t\t\t  autoassign SMALLINT,\r\n\t\t\t\t\t\t\t  approval SMALLINT,\r\n\t\t\t\t\t\t\t  allow_multi SMALLINT,\r\n\t\t\t\t\t\t\t  max_participants INTEGER,\r\n\t\t\t\t\t\t\t  min_notice_time INTEGER,\r\n\t\t\t\t\t\t\t  max_notice_time INTEGER\r\n\t\t\t\t\t\t\t  )", 'Creating resources table'), array("CREATE INDEX rs_scheduleid ON {$resources} (scheduleid)", 'Creating index'), array("CREATE INDEX rs_name ON {$resources} (name)", 'Creating index'), array("CREATE INDEX rs_status ON {$resources} (status)", 'Creating index'), array("CREATE TABLE {$permission} (\r\n\t\t\t\t\t\t\t  memberid CHAR(16) NOT NULL,\r\n\t\t\t\t\t\t\t  machid CHAR(16) NOT NULL,\r\n\t\t\t\t\t\t\t  PRIMARY KEY(memberid, machid)\r\n\t\t\t\t\t\t\t  )", 'Creating permission table'), array("CREATE INDEX per_memberid ON {$permission} (memberid)", 'Creating index'), array("CREATE INDEX per_machid ON {$permission} (machid)", 'Creating index'), array("CREATE TABLE {$schedules} (\r\n\t\t\t\t\t\t\t  scheduleid CHAR(16) NOT NULL PRIMARY KEY,\r\n\t\t\t\t\t\t\t  scheduletitle CHAR(75),\r\n\t\t\t\t\t\t\t  daystart INTEGER NOT NULL,\r\n\t\t\t\t\t\t\t  dayend INTEGER NOT NULL,\r\n\t\t\t\t\t\t\t  timespan INTEGER NOT NULL,\r\n\t\t\t\t\t\t\t  timeformat INTEGER NOT NULL,\r\n\t\t\t\t\t\t\t  weekdaystart INTEGER NOT NULL,\r\n\t\t\t\t\t\t\t  viewdays INTEGER NOT NULL,\r\n\t\t\t\t\t\t\t  usepermissions SMALLINT,\r\n\t\t\t\t\t\t\t  ishidden SMALLINT,\r\n\t\t\t\t\t\t\t  showsummary SMALLINT,\r\n\t\t\t\t\t\t\t  adminemail VARCHAR(75),\r\n\t\t\t\t\t\t\t  isdefault SMALLINT\r\n\t\t\t\t\t\t\t  )", 'Creating table schedules'), array("CREATE INDEX sh_hidden ON {$schedules} (ishidden)", 'Creating index'), array("CREATE INDEX sh_perms ON {$schedules} (usepermissions)", 'Creating index'), array("CREATE TABLE {$schedule_permission} (\r\n\t\t\t\t\t\t\t  scheduleid CHAR(16) NOT NULL,\r\n\t\t\t\t\t\t\t  memberid CHAR(16) NOT NULL,\r\n\t\t\t\t\t\t\t  PRIMARY KEY(scheduleid, memberid)\r\n\t\t\t\t\t\t\t  )", 'Creating table schedule_permission'), array("CREATE INDEX sp_scheduleid ON {$schedule_permission} (scheduleid)", 'Creating index'), array("CREATE INDEX sp_memberid ON {$schedule_permission} (memberid)", 'Creating index'), array("CREATE TABLE {$reservation_users} (\r\n\t\t\t\t\t\t\t  resid CHAR(16) NOT NULL,\r\n\t\t\t\t\t\t\t  memberid CHAR(16) NOT NULL,\r\n\t\t\t\t\t\t\t  owner SMALLINT,\r\n\t\t\t\t\t\t\t  invited SMALLINT,\r\n\t\t\t\t\t\t\t  perm_modify SMALLINT,\r\n\t\t\t\t\t\t\t  perm_delete SMALLINT,\r\n\t\t\t\t\t\t\t  accept_code CHAR(16),\r\n\t\t\t\t\t\t\t  PRIMARY KEY(resid, memberid)\r\n\t\t\t\t\t\t\t  )", 'Creating table reservation_users'), array("CREATE INDEX resusers_resid ON {$reservation_users} (resid)", 'Creating index'), array("CREATE INDEX resusers_memberid ON {$reservation_users} (memberid)", 'Creating index'), array("CREATE INDEX resusers_owner ON {$reservation_users} (owner)", 'Creating index'), array("CREATE TABLE {$anonymous_users} (\r\n\t\t\t\t\t\t\t  memberid CHAR(16) NOT NULL PRIMARY KEY,\r\n\t\t\t\t\t\t\t  email VARCHAR(75) NOT NULL,\r\n\t\t\t\t\t\t\t  fname VARCHAR(30) NOT NULL,\r\n\t\t\t\t\t\t\t  lname VARCHAR(30) NOT NULL\r\n\t\t\t\t\t\t\t  )", 'Creating table anonymous_users'), array("CREATE TABLE {$additional_resources} (\r\n\t\t\t\t\t\t\t  resourceid CHAR(16) NOT NULL PRIMARY KEY,\r\n\t\t\t\t\t\t\t  name VARCHAR(75) NOT NULL,\r\n\t\t\t\t\t\t\t  status CHAR(1) NOT NULL DEFAULT 'a',\r\n\t\t\t\t\t\t\t  number_available INTEGER NOT NULL DEFAULT -1\r\n\t\t\t\t\t\t\t  )", 'Creating table additional_resources'), array("CREATE INDEX ar_name ON {$additional_resources} (name)", 'Creating index'), array("CREATE INDEX ar_status ON {$additional_resources} (status)", 'Creating index'), array("CREATE TABLE {$reservation_resources} (\r\n\t\t\t\t\t\t\t  resid CHAR(16) NOT NULL,\r\n\t\t\t\t\t\t\t  resourceid CHAR(16) NOT NULL,\r\n\t\t\t\t\t\t\t  owner SMALLINT,\r\n\t\t\t\t\t\t\t  PRIMARY KEY(resid, resourceid)\r\n\t\t\t\t\t\t\t  )", 'Creating table reservation_resources'), array("CREATE INDEX resresources_resid ON {$reservation_resources} (resid)", 'Creating index'), array("CREATE INDEX resresources_resourceid ON {$reservation_resources} (resourceid)", 'Creating index'), array("CREATE INDEX resresources_owner ON {$reservation_resources} (owner)", 'Creating index'), array("CREATE TABLE {$mutex} (\r\n\t\t\t\t\t\t\t  i INTEGER NOT NULL PRIMARY KEY\r\n\t\t\t\t\t\t\t  )", 'Creating table mutex'), array("INSERT INTO {$mutex} VALUES (0)", 'Insert values'), array("INSERT INTO {$mutex} VALUES (1)", 'Insert values'), array("CREATE TABLE {$groups} (\r\n\t\t\t\t\t\t\t  groupid CHAR(16) NOT NULL PRIMARY KEY,\r\n\t\t\t\t\t\t\t  group_name VARCHAR(50) NOT NULL\r\n\t\t\t\t\t\t\t  )", 'Creating table groups'), array("CREATE TABLE {$user_groups} (\r\n\t\t\t\t\t\t\t  groupid CHAR(16) NOT NULL,\r\n\t\t\t\t\t\t\t  memberid CHAR(50) NOT NULL,\r\n\t\t\t\t\t\t\t  is_admin SMALLINT NOT NULL DEFAULT 0,\r\n\t\t\t\t\t\t\t  PRIMARY KEY(groupid, memberid)\r\n\t\t\t\t\t\t\t  )", 'Creating table user_groups'), array("CREATE INDEX usergroups_groupid ON {$user_groups} (groupid)", 'Creating index'), array("CREATE INDEX usergroups_memberid ON {$user_groups} (memberid)", 'Creating index'), array("CREATE INDEX usergroups_is_admin ON {$user_groups} (is_admin)", 'Creating index'), array("CREATE TABLE {$reminders} (\r\n\t\t\t\t\t\t\t  reminderid CHAR(16) NOT NULL PRIMARY KEY,\r\n\t\t\t\t\t\t\t  memberid CHAR(16) NOT NULL,\r\n\t\t\t\t\t\t\t  resid CHAR(16) NOT NULL,\r\n\t\t\t\t\t\t\t  reminder_time BIGINT NOT NULL\r\n\t\t\t\t\t\t\t  )", 'Creating table reminders'), array("CREATE INDEX reminders_time ON {$reminders} (reminder_time)", 'Creating index'), array("CREATE INDEX reminders_memberid ON {$reminders} (memberid)", 'Creating index'), array("CREATE INDEX reminders_resid ON {$reminders} (resid)", 'Creating index'), array("grant select, insert, update, delete\r\n\t\t\t\t\t\t\ton {$conf['db']['dbName']}.*\r\n\t\t\t\t\t\t\tto {$conf['db']['dbUser']}@localhost identified by '{$conf['db']['dbPass']}'", 'Creating database user'));
    if ($conf['db']['drop_old']) {
        // Drop any old database with same name
        array_unshift($sqls, array("drop database if exists {$conf['db']['dbName']}", 'Dropping database'));
    }
    foreach ($sqls as $sql) {
        echo $sql[1] . '...';
        $result = $db->query($sql[0]);
        check_result($result);
    }
    $dbe = new DBEngine();
    // Create default schedule
    echo 'Creating default schedule...';
    $scheduleid = $dbe->get_new_id();
    $result = $dbe->db->query("INSERT INTO {$schedules} VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)", array($scheduleid, 'default', 480, 1200, 30, 12, 0, 7, 0, 0, 1, $conf['app']['adminEmail'], 1));
    check_result($result);
}
Example #3
0
    // For each item in the column, with bottom padding included (-4)
    for ($vy = 0; $vy < 17; $vy++) {
        // Check the current position's value and the three tiles below
        $result = $grid[$vy][$vx] * $grid[$vy + 1][$vx] * $grid[$vy + 2][$vx] * $grid[$vy + 3][$vx];
        // Check the new value against the current one
        $product = check_result($result, $product);
    }
}
// Diagonal (left-right)
// For each row going left to right
for ($drx = 0; $drx < 17; $drx++) {
    // For each column going top to bottom
    for ($dry = 0; $dry < 17; $dry++) {
        // Check the current position and three to the bottom right (ie [0,0], [1,1], [2,2], [3,3])
        $result = $grid[$drx][$dry] * $grid[$drx + 1][$dry + 1] * $grid[$drx + 2][$dry + 2] * $grid[$drx + 3][$dry + 3];
        // Check the new value against the current one
        $product = check_result($result, $product);
    }
}
// Diagonal (right-left)
// For each row going right to left
for ($dlx = 19; $dlx > 2; $dlx--) {
    // For each column going top to bottom
    for ($dly = 0; $dly < 17; $dly++) {
        // Check the current position and three to the bottom left (ie [3,0], [2,1], [1,2], [0,3])
        $result = $grid[$dlx][$dly] * $grid[$dlx - 1][$dly + 1] * $grid[$dlx - 2][$dly + 2] * $grid[$dlx - 3][$dly + 3];
        // Check the new value against the current one
        $product = check_result($result, $product);
    }
}
echo 'The greatest product of four adjacent numbers in the same direction in the 20x20 grid is ' . $product;
Example #4
0
function S_A_I_A_D_set_initial_amount_deposited($account_id, $initial_amount_deposited)
{
    global $s_a_con;
    $result = mysql_query("UPDATE s_a_i_a_d SET initial_amount_deposited = '{$initial_amount_deposited}' WHERE account_id = '{$account_id}'", $s_a_con);
    return check_result($result);
}
Example #5
0
        if ($mf_settings['data_dir'] != $mf_settings['upload_dir']) {
            mkdir($mf_settings['upload_dir'] . "/form_{$form_id}", 0777);
        }
        mkdir($mf_settings['upload_dir'] . "/form_{$form_id}/files", 0777);
        //copy default view.css to css folder
        if (copy("./view.css", $mf_settings['data_dir'] . "/form_{$form_id}/css/view.css")) {
            //on success update 'form_has_css' field on ap_forms table
            $form_update_input['form_has_css'] = 1;
            mf_ap_forms_update($form_id, $form_update_input, $dbh);
        }
        umask($old_mask);
    }
} else {
    //If this is old form, only update ap_forms table
    $result = mf_ap_forms_update($form_id, $form_input, $dbh);
    check_result($result);
}
/***************************************************************************************************************/
/* 2. Process fields																					   	   */
/***************************************************************************************************************/
// 2.1 Process new fields
//Get the new fields from ap_form_elements table with status = 2, change the status to 1 and create the field column into the form's table
$query = "SELECT \r\n   \t\t\t\t\telement_id,\r\n   \t\t\t\t\telement_matrix_allow_multiselect \r\n   \t\t\t\tFROM \r\n   \t\t\t\t\t" . MF_TABLE_PREFIX . "form_elements \r\n   \t\t\t   WHERE \r\n   \t\t\t   \t\tform_id = ? and element_type='matrix' and element_matrix_parent_id=0";
$params = array($form_id);
$sth = mf_do_query($query, $params, $dbh);
while ($row = mf_do_fetch_result($sth)) {
    $matrix_multiselect_settings[$row['element_id']] = $row['element_matrix_allow_multiselect'];
}
$matrix_child_array = array();
$query = "SELECT \r\n   \t\t\t\t\telement_id, element_type,\r\n   \t\t\t\t\telement_constraint,element_position,\r\n   \t\t\t\t\telement_matrix_parent_id,\r\n   \t\t\t\t\telement_matrix_allow_multiselect,\r\n   \t\t\t\t\telement_choice_has_other \r\n   \t\t\t\tFROM \r\n   \t\t\t\t\t" . MF_TABLE_PREFIX . "form_elements \r\n   \t\t\t   WHERE \r\n   \t\t\t   \t\tform_id = ? and element_status=2 \r\n   \t\t\tORDER BY \r\n   \t\t\t\t\telement_position asc";
$params = array($form_id);
    // Emulates PS first
    $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
    $db->exec('SET @numcols = 1');
    $stmt = $db->prepare('CALL p()');
    $stmt->execute();
    check_result(11, $stmt, 1);
    $stmt->execute();
    check_result(12, $stmt, 2);
    $db->exec('SET @numcols = 1');
    $stmt->execute();
    check_result(13, $stmt, 1);
    if (MySQLPDOTest::isPDOMySQLnd()) {
        // Native PS
        // Libmysql cannot handle such a stored procedure. You will see leaks with libmysql
        $db = MySQLPDOTest::factory();
        $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
        $db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, 1);
        $db->exec('SET @numcols = 1');
        $stmt = $db->prepare('CALL p()');
        $stmt->execute();
        check_result(14, $stmt, 1);
        $stmt->execute();
        check_result(15, $stmt, 2);
        $db->exec('SET @numcols = 1');
        $stmt->execute();
        check_result(16, $stmt, 1);
    }
} catch (PDOException $e) {
    printf("[99] %s [%s] %s\n", $e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo()));
}
print "done!";
Example #7
0
/**
* Create the database and the tables in it
* @param string $version current version of phpScheduleIt that we are upgrading from
*/
function doUpdate($version)
{
    global $db;
    global $conf;
    $dbe = new DBEngine();
    $announcements = $dbe->get_table('announcements');
    $reservations = $dbe->get_table('reservations');
    $resources = $dbe->get_table('resources');
    $login = $dbe->get_table('login');
    $reservation_users = $dbe->get_table('reservation_users');
    $anonymous_users = $dbe->get_table('anonymous_users');
    $additional_resources = $dbe->get_table('additional_resources');
    $reservation_resources = $dbe->get_table('reservation_resources');
    $mutex = $dbe->get_table('mutex');
    $schedules = $dbe->get_table('schedules');
    $groups = $dbe->get_table('groups');
    $user_groups = $dbe->get_table('user_groups');
    $reminders = $dbe->get_table('reminders');
    //# Since version 1.1.0
    $create_announcements = array("CREATE TABLE {$announcements} (\r\n\t\t\t\t\t\t\t\t\t  announcementid CHAR(16) NOT NULL PRIMARY KEY,\r\n\t\t\t\t\t\t\t\t\t  announcement CHAR(255) NOT NULL DEFAULT '',\r\n\t\t\t\t\t\t\t\t\t  number SMALLINT NOT NULL DEFAULT 0,\r\n\t\t\t\t\t\t\t\t\t  start_datetime INT,\r\n  \t\t\t\t\t\t\t\t\t  end_datetime INT\r\n\t\t\t\t\t\t\t\t\t  )", 'Creating announcements table');
    $create_announcements_sdt_index = array("create index announcements_startdatetime on {$announcements}(start_datetime)", 'Create start_datetime index');
    $create_announcements_edt_index = array("create index announcements_enddatetime on {$announcements}(end_datetime)", 'Create end_datetime index');
    $alter_reservations_add_ispending = array("ALTER TABLE {$reservations} ADD COLUMN is_pending SMALLINT NOT NULL DEFAULT 0 AFTER is_blackout", 'Add is_pending column');
    $create_reservations_ispending_index = array("CREATE INDEX reservations_ispending ON {$reservations} (is_pending)", 'Add is_pending index');
    $alter_resources_add_approval = array("ALTER TABLE {$resources} ADD COLUMN approval SMALLINT", 'Add approval column');
    $alter_login_add_eapp = array("ALTER TABLE {$login} ADD COLUMN e_app CHAR(1) NOT NULL DEFAULT 'y' AFTER e_del", 'Add e_app column');
    $alter_login_add_logonname = array("ALTER TABLE {$login} ADD COLUMN logon_name CHAR(30)", 'Add logon_name column');
    $create_login_logonname_index = array("CREATE INDEX login_logonname ON {$login} (logon_name)", 'Add logon_name index');
    $alter_reservations_add_startdate = array("ALTER TABLE {$reservations} ADD COLUMN start_date int NOT NULL DEFAULT 0 AFTER date", 'Add start_date column');
    $alter_reservations_add_enddate = array("ALTER TABLE {$reservations} ADD COLUMN end_date int NOT NULL DEFAULT 0 AFTER start_date", 'Add end_date column');
    $create_reservations_index_startdate = array("CREATE INDEX reservations_startdate ON {$reservations} (start_date)", 'Add start_date index');
    $create_reservations_index_enddate = array("CREATE INDEX reservations_enddate ON {$reservations} (end_date)", 'Add end_date index');
    $update_reservations_set_startdate = array("UPDATE {$reservations} SET start_date = date", 'Set start_date = date');
    $update_reservations_set_enddate = array("UPDATE {$reservations} SET end_date = date", 'Set end_date = date');
    $alter_reservations_drop_date = array("ALTER TABLE {$reservations} DROP COLUMN date", 'Drop date column');
    $alter_resources_add_allowmulti = array("ALTER TABLE {$resources} ADD COLUMN allow_multi SMALLINT", 'Add allow_multi column');
    $create_reservation_users = array("CREATE TABLE {$reservation_users} (\r\n\t\t\t\t\t\t\t\t\t  resid CHAR(16) NOT NULL,\r\n\t\t\t\t\t\t\t\t\t  memberid CHAR(16) NOT NULL,\r\n\t\t\t\t\t\t\t\t\t  owner smallint,\r\n\t\t\t\t\t\t\t\t\t  invited smallint,\r\n\t\t\t\t\t\t\t\t\t  perm_modify smallint,\r\n\t\t\t\t\t\t\t\t\t  perm_delete smallint,\r\n\t\t\t\t\t\t\t\t\t  accept_code char(16),\r\n\t\t\t\t\t\t\t\t\t  primary key(resid, memberid)\r\n\t\t\t\t\t\t\t\t\t  )", 'Create reservation_users table');
    $create_reservationusers_resid_index = array("create index resusers_resid on {$reservation_users} (resid)", 'Create resusers_resid index');
    $create_reservationusers_memberid_index = array("create index resusers_memberid on {$reservation_users} (memberid)", 'Create resusers_memberid index');
    $create_reservationusers_owner_index = array("create index resusers_owner on {$reservation_users} (owner)", 'Create resusers_owner index');
    $migrate_users = array("insert into {$reservation_users} select resid, memberid, 1, 0, 0, 0, null from {$reservations}", 'Migrating users');
    $alter_reservations_drop_memberid = array("alter table {$reservations} drop column memberid, drop index res_memberid", 'Drop memberid column');
    $alter_login_add_isadmin = array("alter table {$login} add column is_admin smallint default 0", 'Create is_admin on login');
    // Array of all SQL statements to run to upgrade to version 1.1.0
    $version110 = array($create_announcements, $create_announcements_sdt_index, $create_announcements_edt_index, $alter_reservations_add_ispending, $create_reservations_ispending_index, $alter_resources_add_approval, $alter_login_add_eapp, $alter_login_add_logonname, $create_login_logonname_index, $alter_reservations_add_startdate, $alter_reservations_add_enddate, $create_reservations_index_startdate, $create_reservations_index_enddate, $update_reservations_set_startdate, $update_reservations_set_enddate, $alter_reservations_drop_date, $alter_resources_add_allowmulti, $create_reservation_users, $create_reservationusers_resid_index, $create_reservationusers_memberid_index, $create_reservationusers_owner_index, $migrate_users, $alter_reservations_drop_memberid, $alter_login_add_isadmin);
    //!#----------------
    //# Since version 1.2.0
    $create_resources_max_participants = array("ALTER TABLE {$resources} ADD COLUMN max_participants INTEGER", 'Create column max_participants');
    $create_reservations_allow_participation = array("ALTER TABLE {$reservations} ADD COLUMN allow_participation smallint not null default 0", 'Create column allow_participation');
    $create_reservations_allow_anon_participation = array("ALTER TABLE {$reservations} ADD COLUMN allow_anon_participation smallint not null default 0", 'Create column allow_anon_participation');
    $create_anonymous_users_table = array("CREATE TABLE {$anonymous_users} (\r\n\t\t\t\t\t\t\t\t\t\t\t  memberid CHAR(16) NOT NULL PRIMARY KEY,\r\n\t\t\t\t\t\t\t\t\t\t\t  email VARCHAR(75) NOT NULL,\r\n\t\t\t\t\t\t\t\t\t\t\t  fname VARCHAR(30) NOT NULL,\r\n\t\t\t\t\t\t\t\t\t\t\t  lname VARCHAR(30) NOT NULL\r\n\t\t\t\t\t\t\t\t\t\t\t  )", 'Create anonymous_users table');
    $create_additional_resources = array("CREATE TABLE {$additional_resources} (\r\n\t\t\t\t\t\t\t\t\t\t\t  resourceid CHAR(16) NOT NULL PRIMARY KEY,\r\n\t\t\t\t\t\t\t\t\t\t\t  name VARCHAR(75) NOT NULL,\r\n\t\t\t\t\t\t\t\t\t\t\t  status CHAR(1) NOT NULL DEFAULT 'a',\r\n\t\t\t\t\t\t\t\t\t\t\t  number_available INTEGER NOT NULL DEFAULT -1\r\n\t\t\t\t\t\t\t\t\t\t\t  )", 'Create additional_resources table');
    $create_ar_name_index = array("CREATE INDEX ar_name ON {$additional_resources} (name)", 'Create index');
    $create_ar_status_index = array("CREATE INDEX ar_status ON {$additional_resources} (status)", 'Create index');
    $create_reservation_resources = array("CREATE TABLE {$reservation_resources} (\r\n\t\t\t\t\t\t\t\t\t\t\t  resid CHAR(16) NOT NULL,\r\n\t\t\t\t\t\t\t\t\t\t\t  resourceid CHAR(16) NOT NULL,\r\n\t\t\t\t\t\t\t\t\t\t\t  owner SMALLINT,\r\n\t\t\t\t\t\t\t\t\t\t\t  PRIMARY KEY(resid, resourceid)\r\n\t\t\t\t\t\t\t\t\t\t\t  )", 'Create reservation_resources table');
    $create_resresources_resid_index = array("CREATE INDEX resresources_resid ON {$reservation_resources} (resid)", 'Create index');
    $create_resresources_resourceid_index = array("CREATE INDEX resresources_resourceid ON {$reservation_resources} (resourceid)", 'Create index');
    $create_resresources_owner_index = array("CREATE INDEX resresources_owner ON {$reservation_resources} (owner)", 'Create index');
    $create_mutex_table = array("CREATE TABLE {$mutex}(\r\n\t\t\t\t\t\t\t\t  i INTEGER NOT NULL PRIMARY KEY\r\n\t\t\t\t\t\t\t\t  )", 'Create mutex table');
    $insert_mutex_value0 = array("INSERT INTO {$mutex} VALUES (0)", 'Insert value');
    $insert_mutex_value1 = array("INSERT INTO {$mutex} VALUES (1)", 'Insert value');
    $alter_starttime = array("ALTER TABLE {$reservations} CHANGE startTime starttime INTEGER NOT NULL", 'Alter table');
    $alter_endtime = array("ALTER TABLE {$reservations} CHANGE endTime endtime INTEGER NOT NULL", 'Alter table');
    $alter_minres = array("ALTER TABLE {$resources} CHANGE minRes minres INTEGER NOT NULL", 'Alter table');
    $alter_maxres = array("ALTER TABLE {$resources} CHANGE maxRes maxres INTEGER NOT NULL", 'Alter table');
    $alter_autoassign = array("ALTER TABLE {$resources} CHANGE autoAssign autoassign SMALLINT", 'Alter table');
    $alter_scheduletitle = array("ALTER TABLE {$schedules} CHANGE scheduleTitle scheduletitle CHAR(75)", 'Alter table');
    $alter_daystart = array("ALTER TABLE {$schedules} CHANGE dayStart daystart INTEGER NOT NULL", 'Alter table');
    $alter_dayend = array("ALTER TABLE {$schedules} CHANGE dayEnd dayend INTEGER NOT NULL", 'Alter table');
    $alter_timespan = array("ALTER TABLE {$schedules} CHANGE timeSpan timespan INTEGER NOT NULL", 'Alter table');
    $alter_timeformat = array("ALTER TABLE {$schedules} CHANGE timeFormat timeformat INTEGER NOT NULL", 'Alter table');
    $alter_weekdaystart = array("ALTER TABLE {$schedules} CHANGE weekDayStart weekdaystart INTEGER NOT NULL", 'Alter table');
    $alter_viewdays = array("ALTER TABLE {$schedules} CHANGE viewDays viewdays INTEGER NOT NULL", 'Alter table');
    $alter_usepermissions = array("ALTER TABLE {$schedules} CHANGE usePermissions usepermissions SMALLINT", 'Alter table');
    $alter_ishidden = array("ALTER TABLE {$schedules} CHANGE isHidden ishidden SMALLINT", 'Alter table');
    $alter_showsummary = array("ALTER TABLE {$schedules} CHANGE showSummary showsummary SMALLINT", 'Alter table');
    $alter_adminemail = array("ALTER TABLE {$schedules} CHANGE adminEmail adminemail CHAR(75)", 'Alter table');
    $alter_isdefault = array("ALTER TABLE {$schedules} CHANGE isDefault isdefault SMALLINT", 'Alter table');
    $create_groups = array("CREATE TABLE {$groups} (\r\n\t\t\t\t\t\t\t  groupid CHAR(16) NOT NULL PRIMARY KEY,\r\n\t\t\t\t\t\t\t  group_name VARCHAR(50) NOT NULL\r\n\t\t\t\t\t\t\t  )", 'Create groups table');
    $create_user_groups = array("CREATE TABLE {$user_groups} (\r\n\t\t\t\t\t\t\t  groupid CHAR(16) NOT NULL,\r\n\t\t\t\t\t\t\t  memberid CHAR(50) NOT NULL,\r\n\t\t\t\t\t\t\t  is_admin SMALLINT NOT NULL DEFAULT 0,\r\n\t\t\t\t\t\t\t  PRIMARY KEY(groupid, memberid)\r\n\t\t\t\t\t\t\t  )", 'Creating table user_groups');
    $create_usergroups_groupid_index = array("CREATE INDEX usergroups_groupid ON {$user_groups} (groupid)", 'Create index');
    $create_usergroups_memberid_index = array("CREATE INDEX usergroups_memberid ON {$user_groups} (memberid)", 'Create index');
    $create_usergroups_is_admin_index = array("CREATE INDEX usergroups_is_admin ON {$user_groups} (is_admin)", 'Create index');
    $create_reminders = array("CREATE TABLE {$reminders} (\r\n\t\t\t\t\t\t\t  reminderid CHAR(16) NOT NULL PRIMARY KEY,\r\n\t\t\t\t\t\t\t  memberid CHAR(16) NOT NULL,\r\n\t\t\t\t\t\t\t  resid CHAR(16) NOT NULL,\r\n\t\t\t\t\t\t\t  reminder_time BIGINT NOT NULL\r\n\t\t\t\t\t\t\t  )", 'Create reminders table');
    $create_reminders_time_index = array("CREATE INDEX reminders_time ON {$reminders} (reminder_time)", 'Create index');
    $create_reminders_memberid_index = array("CREATE INDEX reminders_memberid ON {$reminders} (memberid)", 'Create index');
    $create_reminders_resid_index = array("CREATE INDEX reminders_resid ON {$reminders} (resid)", 'Create index');
    $alter_login_add_lang = array("ALTER TABLE {$login} ADD COLUMN lang VARCHAR(5)", 'Add lang');
    $alter_login_add_timezone = array("ALTER TABLE {$login} ADD COLUMN timezone FLOAT NOT NULL DEFAULT 0", 'Add timezone');
    $alter_resources_add_minnotice = array("ALTER TABLE {$resources} ADD COLUMN min_notice_time INTEGER NOT NULL DEFAULT 0", 'Add min_notice_time');
    $alter_resources_add_maxnotice = array("ALTER TABLE {$resources} ADD COLUMN max_notice_time INTEGER NOT NULL DEFAULT 0", 'Add max_notice_time');
    $update_resources_set_mintime = array("UPDATE {$resources} r, {$schedules} s SET min_notice_time = dayoffset * 24 WHERE r.scheduleid = s.scheduleid AND dayoffset IS NOT NULL", 'Set min_notice_time');
    $alter_schedules_drop_dayoffset = array("ALTER TABLE {$schedules} DROP COLUMN dayoffset", 'Drop dayoffset');
    $version120 = array($create_resources_max_participants, $create_reservations_allow_participation, $create_reservations_allow_anon_participation, $create_anonymous_users_table, $create_additional_resources, $create_ar_name_index, $create_ar_status_index, $create_reservation_resources, $create_resresources_resid_index, $create_resresources_resourceid_index, $create_resresources_owner_index, $create_mutex_table, $insert_mutex_value0, $insert_mutex_value1, $alter_starttime, $alter_endtime, $alter_minres, $alter_maxres, $alter_autoassign, $alter_scheduletitle, $alter_daystart, $alter_dayend, $alter_timespan, $alter_timeformat, $alter_weekdaystart, $alter_viewdays, $alter_usepermissions, $alter_ishidden, $alter_showsummary, $alter_adminemail, $alter_isdefault, $create_groups, $create_user_groups, $create_usergroups_groupid_index, $create_usergroups_memberid_index, $create_usergroups_is_admin_index, $create_reminders, $create_reminders_time_index, $create_reminders_memberid_index, $create_reminders_resid_index, $alter_login_add_lang, $alter_login_add_timezone, $alter_resources_add_minnotice, $alter_resources_add_maxnotice, $update_resources_set_mintime, $alter_schedules_drop_dayoffset);
    //!#----------------
    //# Must run for all updates
    $select_db = array(array("use {$conf['db']['dbName']}", 'Selecting database'));
    $to_run[] = $select_db;
    //#
    if ($version == "1.0.0") {
        $to_run[] = $version110;
        $to_run[] = $version120;
    } else {
        if ($version = "1.1.0") {
            $to_run[] = $version120;
        }
    }
    foreach ($to_run as $sqls) {
        foreach ($sqls as $sql) {
            echo $sql[1] . '...';
            $result = $db->query($sql[0]);
            check_result($result);
        }
    }
}
Example #8
0
function ut_main()
{
    $res_str = '';
    $char_a_diaeresis = "ä";
    // 'LATIN SMALL LETTER A WITH DIAERESIS' (U+00E4)
    $char_a_ring = "å";
    // 'LATIN SMALL LETTER A WITH RING ABOVE' (U+00E5)
    $char_o_diaeresis = "ö";
    // 'LATIN SMALL LETTER O WITH DIAERESIS' (U+00F6)
    $char_O_diaeresis = "Ö";
    // 'LATIN CAPITAL LETTER O WITH DIAERESIS' (U+00D6)
    $char_angstrom_sign = "Å";
    // 'ANGSTROM SIGN' (U+212B)
    $char_A_ring = "Å";
    // 'LATIN CAPITAL LETTER A WITH RING ABOVE' (U+00C5)
    $char_ohm_sign = "Ω";
    // 'OHM SIGN' (U+2126)
    $char_omega = "Ω";
    // 'GREEK CAPITAL LETTER OMEGA' (U+03A9)
    $char_combining_ring_above = "̊";
    // 'COMBINING RING ABOVE' (U+030A)
    $char_fi_ligature = "fi";
    // 'LATIN SMALL LIGATURE FI' (U+FB01)
    $char_long_s_dot = "ẛ";
    // 'LATIN SMALL LETTER LONG S WITH DOT ABOVE' (U+1E9B)
    // the word 'hindi' using Devanagari characters:
    $hindi = "हिन्दी";
    $char_a_ring_nfd = "å";
    $char_A_ring_nfd = "Å";
    $char_o_diaeresis_nfd = "ö";
    $char_O_diaeresis_nfd = "Ö";
    $char_diaeresis = "̈";
    //=====================================================================================
    $res_str .= "\n" . 'function grapheme_strlen($string) {}' . "\n\n";
    $res_str .= "\"hindi\" in devanagari strlen " . grapheme_strlen($hindi) . "\n";
    $res_str .= "\"ab\" + \"hindi\" + \"cde\" strlen " . grapheme_strlen('ab' . $hindi . 'cde') . "\n";
    $res_str .= "\"\" strlen " . grapheme_strlen("") . "\n";
    $res_str .= "char_a_ring_nfd strlen " . grapheme_strlen($char_a_ring_nfd) . "\n";
    $res_str .= "char_a_ring_nfd + \"bc\" strlen " . grapheme_strlen($char_a_ring_nfd . 'bc') . "\n";
    $res_str .= "\"abc\" strlen " . grapheme_strlen('abc') . "\n";
    //=====================================================================================
    $res_str .= "\n" . 'function grapheme_strpos($haystack, $needle, $offset = 0) {}' . "\n\n";
    $tests = array(array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "o", "o", 5), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd, "o", "false"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd, $char_o_diaeresis_nfd, 4), array($char_o_diaeresis_nfd . "a" . $char_a_ring_nfd . "bc", $char_a_ring_nfd, 2), array("a" . $char_a_ring_nfd . "bc", $char_a_ring_nfd, 1), array("abc", $char_a_ring_nfd, "false"), array($char_a_ring_nfd . "bc", "a", "false"), array("abc", "d", "false"), array("abc", "c", 2), array("abc", "b", 1), array("abc", "a", 0), array("abc", "a", 0, 0), array("abc", "a", 1, "false"), array("ababc", "a", 1, 2), array("ao" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "o", "o", 2, 6), array($char_o_diaeresis_nfd . $char_a_ring_nfd . "a" . $char_a_ring_nfd . "bc", $char_a_ring_nfd, 2, 3), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "opq", "op", 5), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "opq", "opq", 5), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd, "abc", "false"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "bc" . $char_o_diaeresis_nfd, $char_o_diaeresis_nfd . "bc" . $char_o_diaeresis_nfd, 4), array($char_o_diaeresis_nfd . "a" . $char_a_ring_nfd . "bc", $char_a_ring_nfd . "bc", 2), array("a" . $char_a_ring_nfd . "bc", $char_a_ring_nfd . "bc", 1), array("abc", $char_a_ring_nfd . "bc", "false"), array($char_a_ring_nfd . "bc", "abcdefg", "false"), array("abc", "defghijklmnopq", "false"), array("abc", "ab", 0), array("abc", "bc", 1), array("abc", "abc", 0), array("abc", "abcd", "false"), array("abc", "ab", 0, 0), array("abc", "abc", 0, 0), array("abc", "abc", 1, "false"), array("ababc", "ab", 1, 2), array("ababc", "abc", 1, 2), array("ao" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "o" . $char_a_ring_nfd . "bc", "o" . $char_a_ring_nfd . "bc", 2, 6), array($char_o_diaeresis_nfd . $char_a_ring_nfd . "a" . $char_a_ring_nfd . "bc" . $char_a_ring_nfd . "def", $char_a_ring_nfd . "bc" . $char_a_ring_nfd, 2, 3));
    foreach ($tests as $test) {
        $arg1 = urlencode($test[1]);
        $arg0 = urlencode($test[0]);
        $res_str .= "find \"{$arg1}\" in \"{$arg0}\" - grapheme_strpos";
        if (3 == count($test)) {
            $result = grapheme_strpos($test[0], $test[1]);
        } else {
            $res_str .= " from {$test['2']}";
            $result = grapheme_strpos($test[0], $test[1], $test[2]);
        }
        $res_str .= " = ";
        if ($result === false) {
            $res_str .= 'false';
        } else {
            $res_str .= $result;
        }
        $res_str .= " == " . $test[count($test) - 1] . check_result($result, $test[count($test) - 1]) . "\n";
    }
    //=====================================================================================
    $res_str .= "\n" . 'function grapheme_stripos($haystack, $needle, $offset = 0) {}' . "\n\n";
    $tests = array(array("ao" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "O", "o", 2, 6), array($char_o_diaeresis_nfd . $char_a_ring_nfd . "a" . $char_A_ring_nfd . "bc", $char_a_ring_nfd, 2, 3), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "O", "o", 5), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd, "O", "false"), array("a" . $char_a_ring_nfd . "bc" . $char_O_diaeresis_nfd, $char_o_diaeresis_nfd, 4), array($char_o_diaeresis_nfd . "a" . $char_a_ring_nfd . "bc", $char_A_ring_nfd, 2), array("a" . $char_A_ring_nfd . "bc", $char_a_ring_nfd, 1), array("Abc", $char_a_ring_nfd, "false"), array($char_a_ring_nfd . "bc", "A", "false"), array("abc", "D", "false"), array("abC", "c", 2), array("abc", "B", 1), array("Abc", "a", 0), array("abc", "A", 0, 0), array("Abc", "a", 1, "false"), array("ababc", "A", 1, 2), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", "oP", 5), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", "opQ", 5), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd, "abc", "false"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "bC" . $char_o_diaeresis_nfd, $char_O_diaeresis_nfd . "bc" . $char_o_diaeresis_nfd, 4), array($char_o_diaeresis_nfd . "a" . $char_a_ring_nfd . "Bc", $char_A_ring_nfd . "bc", 2), array("a" . $char_a_ring_nfd . "BC", $char_a_ring_nfd . "bc", 1), array("abc", $char_a_ring_nfd . "BC", "false"), array($char_a_ring_nfd . "BC", "aBCdefg", "false"), array("aBC", "Defghijklmnopq", "false"), array("abC", "Ab", 0), array("aBC", "bc", 1), array("abC", "Abc", 0), array("abC", "aBcd", "false"), array("ABc", "ab", 0, 0), array("aBc", "abC", 0, 0), array("abc", "aBc", 1, "false"), array("ABabc", "AB", 1, 2), array("abaBc", "aBc", 1, 2), array("ao" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "o" . $char_A_ring_nfd . "bC", "O" . $char_a_ring_nfd . "bC", 2, 6), array($char_o_diaeresis_nfd . $char_a_ring_nfd . "a" . $char_A_ring_nfd . "bC" . $char_a_ring_nfd . "def", $char_a_ring_nfd . "Bc" . $char_a_ring_nfd, 2, 3));
    foreach ($tests as $test) {
        $arg1 = urlencode($test[1]);
        $arg0 = urlencode($test[0]);
        $res_str .= "find \"{$arg1}\" in \"{$arg0}\" - grapheme_stripos";
        if (3 == count($test)) {
            $result = grapheme_stripos($test[0], $test[1]);
        } else {
            $res_str .= " from {$test['2']}";
            $result = grapheme_stripos($test[0], $test[1], $test[2]);
        }
        $res_str .= " = ";
        if ($result === false) {
            $res_str .= 'false';
        } else {
            $res_str .= $result;
        }
        $res_str .= " == " . $test[count($test) - 1] . check_result($result, $test[count($test) - 1]) . "\n";
    }
    //=====================================================================================
    $res_str .= "\n" . 'function grapheme_strrpos($haystack, $needle, $offset = 0) {}' . "\n\n";
    $tests = array(array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "o", "o", 5), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd, "o", "false"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd, $char_o_diaeresis_nfd, 4), array($char_o_diaeresis_nfd . "a" . $char_a_ring_nfd . "bc", $char_a_ring_nfd, 2), array("a" . $char_a_ring_nfd . "bc", $char_a_ring_nfd, 1), array("abc", $char_a_ring_nfd, "false"), array($char_a_ring_nfd . "bc", "a", "false"), array("abc", "d", "false"), array("abc", "c", 2), array("abc", "b", 1), array("abc", "a", 0), array("abc", "a", 0, 0), array("abc", "a", 1, "false"), array("ababc", "a", 1, 2), array("ao" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "o", "o", 2, 6), array($char_o_diaeresis_nfd . $char_a_ring_nfd . "a" . $char_a_ring_nfd . "bc", $char_a_ring_nfd, 2, 3), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "opq", "op", 5), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "opq", "opq", 5), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd, "abc", "false"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "bc" . $char_o_diaeresis_nfd, $char_o_diaeresis_nfd . "bc" . $char_o_diaeresis_nfd, 4), array($char_o_diaeresis_nfd . "a" . $char_a_ring_nfd . "bc", $char_a_ring_nfd . "bc", 2), array("a" . $char_a_ring_nfd . "bc", $char_a_ring_nfd . "bc", 1), array("abc", $char_a_ring_nfd . "bc", "false"), array($char_a_ring_nfd . "bc", "abcdefg", "false"), array("abc", "defghijklmnopq", "false"), array("abc", "ab", 0), array("abc", "bc", 1), array("abc", "abc", 0), array("abc", "abcd", "false"), array("abc", "ab", 0, 0), array("abc", "abc", 0, 0), array("abc", "abc", 1, "false"), array("ababc", "ab", 1, 2), array("ababc", "abc", 1, 2), array("ao" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "o" . $char_a_ring_nfd . "bc", "o" . $char_a_ring_nfd . "bc", 2, 6), array($char_o_diaeresis_nfd . $char_a_ring_nfd . "a" . $char_a_ring_nfd . "bc" . $char_a_ring_nfd . "def", $char_a_ring_nfd . "bc" . $char_a_ring_nfd, 2, 3));
    foreach ($tests as $test) {
        $arg1 = urlencode($test[1]);
        $arg0 = urlencode($test[0]);
        $res_str .= "find \"{$arg1}\" in \"{$arg0}\" - grapheme_strrpos";
        if (3 == count($test)) {
            $result = grapheme_strrpos($test[0], $test[1]);
        } else {
            $res_str .= " from {$test['2']}";
            $result = grapheme_strrpos($test[0], $test[1], $test[2]);
        }
        $res_str .= " = ";
        if ($result === false) {
            $res_str .= 'false';
        } else {
            $res_str .= $result;
        }
        $res_str .= " == " . $test[count($test) - 1] . check_result($result, $test[count($test) - 1]) . "\n";
    }
    //=====================================================================================
    $res_str .= "\n" . 'function grapheme_strripos($haystack, $needle, $offset = 0) {}' . "\n\n";
    $tests = array(array("ao" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "O", "o", 2, 6), array($char_o_diaeresis_nfd . $char_a_ring_nfd . "a" . $char_A_ring_nfd . "bc", $char_a_ring_nfd, 2, 3), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "O", "o", 5), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd, "O", "false"), array("a" . $char_a_ring_nfd . "bc" . $char_O_diaeresis_nfd, $char_o_diaeresis_nfd, 4), array($char_o_diaeresis_nfd . "a" . $char_a_ring_nfd . "bc", $char_A_ring_nfd, 2), array("a" . $char_A_ring_nfd . "bc", $char_a_ring_nfd, 1), array("Abc", $char_a_ring_nfd, "false"), array($char_a_ring_nfd . "bc", "A", "false"), array("abc", "D", "false"), array("abC", "c", 2), array("abc", "B", 1), array("Abc", "a", 0), array("abc", "A", 0, 0), array("Abc", "a", 1, "false"), array("ababc", "A", 1, 2), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", "oP", 5), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", "opQ", 5), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd, "abc", "false"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "bC" . $char_o_diaeresis_nfd, $char_O_diaeresis_nfd . "bc" . $char_o_diaeresis_nfd, 4), array($char_o_diaeresis_nfd . "a" . $char_a_ring_nfd . "Bc", $char_A_ring_nfd . "bc", 2), array("a" . $char_a_ring_nfd . "BC", $char_a_ring_nfd . "bc", 1), array("abc", $char_a_ring_nfd . "BC", "false"), array($char_a_ring_nfd . "BC", "aBCdefg", "false"), array("aBC", "Defghijklmnopq", "false"), array("abC", "Ab", 0), array("aBC", "bc", 1), array("abC", "Abc", 0), array("abC", "aBcd", "false"), array("ABc", "ab", 0, 0), array("aBc", "abC", 0, 0), array("abc", "aBc", 1, "false"), array("ABabc", "AB", 1, 2), array("abaBc", "aBc", 1, 2), array("ao" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "o" . $char_A_ring_nfd . "bC", "O" . $char_a_ring_nfd . "bC", 2, 6), array($char_o_diaeresis_nfd . $char_a_ring_nfd . "a" . $char_A_ring_nfd . "bC" . $char_a_ring_nfd . "def", $char_a_ring_nfd . "Bc" . $char_a_ring_nfd, 2, 3));
    foreach ($tests as $test) {
        $arg1 = urlencode($test[1]);
        $arg0 = urlencode($test[0]);
        $res_str .= "find \"{$arg1}\" in \"{$arg0}\" - grapheme_strripos";
        if (3 == count($test)) {
            $result = grapheme_strripos($test[0], $test[1]);
        } else {
            $res_str .= " from {$test['2']}";
            $result = grapheme_strripos($test[0], $test[1], $test[2]);
        }
        $res_str .= " = ";
        if ($result === false) {
            $res_str .= 'false';
        } else {
            $res_str .= $result;
        }
        $res_str .= " == " . $test[count($test) - 1] . check_result($result, $test[count($test) - 1]) . "\n";
    }
    //=====================================================================================
    $res_str .= "\n" . 'function grapheme_substr($string, $start, $length = -1) {}' . "\n\n";
    $tests = array(array("abc", 3, "false"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd, 5, "false"), array("ao" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "O", 2, $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "O"), array($char_o_diaeresis_nfd . $char_a_ring_nfd . "a" . $char_A_ring_nfd . "bc", 2, "a" . $char_A_ring_nfd . "bc"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "O", 5, "O"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd, 5, "false"), array("a" . $char_a_ring_nfd . "bc" . $char_O_diaeresis_nfd, 4, $char_O_diaeresis_nfd), array($char_o_diaeresis_nfd . "a" . $char_a_ring_nfd . "bc", 2, $char_a_ring_nfd . "bc"), array("a" . $char_A_ring_nfd . "bc", 1, $char_A_ring_nfd . "bc"), array("Abc", -5, "false"), array($char_a_ring_nfd . "bc", 3, "false"), array("abc", 4, "false"), array("abC", 2, "C"), array("abc", 1, "bc"), array("Abc", 1, 1, "b"), array("abc", 0, 2, "ab"), array("Abc", -4, 1, "false"), array("ababc", 1, 2, "ba"), array("ababc", 0, 10, "ababc"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", 0, 10, "a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", 5, "Opq"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", 5, -1, "Op"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", 5, -2, "O"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", 5, -3, ""), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", 5, -4, "false"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", 0, "a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", 0, -1, "a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Op"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", 0, -2, "a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "O"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", 0, -3, "a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", 0, -4, "a" . $char_a_ring_nfd . "bc"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", 0, -5, "a" . $char_a_ring_nfd . "b"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", 0, -6, "a" . $char_a_ring_nfd), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", 0, -7, "a"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", 0, -8, ""), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", 0, -9, "false"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, "a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -7, $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -6, "bc" . $char_o_diaeresis_nfd . "Opq"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -5, "c" . $char_o_diaeresis_nfd . "Opq"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -4, $char_o_diaeresis_nfd . "Opq"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -3, "Opq"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -2, "pq"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -1, "q"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -999, "false"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, 8, "a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, 7, "a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Op"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, 6, "a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "O"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, 5, "a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, 4, "a" . $char_a_ring_nfd . "bc"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, 3, "a" . $char_a_ring_nfd . "b"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, 2, "a" . $char_a_ring_nfd), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, 1, "a"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, 0, ""), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, -999, "false"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, -1, "a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Op"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, -2, "a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "O"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, -3, "a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, -4, "a" . $char_a_ring_nfd . "bc"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, -5, "a" . $char_a_ring_nfd . "b"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, -6, "a" . $char_a_ring_nfd), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, -7, "a"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, -8, ""), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, -9, "false"));
    foreach ($tests as $test) {
        $arg0 = urlencode($test[0]);
        $res_str .= "substring of \"{$arg0}\" from \"{$test['1']}\" - grapheme_substr";
        if (3 == count($test)) {
            $result = grapheme_substr($test[0], $test[1]);
        } else {
            $res_str .= " with length {$test['2']}";
            $result = grapheme_substr($test[0], $test[1], $test[2]);
        }
        $res_str .= " = ";
        if ($result === false) {
            $res_str .= 'false';
        } else {
            $res_str .= urlencode($result);
        }
        $res_str .= " == " . urlencode($test[count($test) - 1]) . check_result($result, $test[count($test) - 1]) . "\n";
    }
    //=====================================================================================
    $res_str .= "\n" . 'function grapheme_strstr($haystack, $needle, $before_needle = FALSE) {}' . "\n\n";
    $tests = array(array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "o", "o", "o"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd, "o", "false"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd, $char_o_diaeresis_nfd, $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . "a" . $char_a_ring_nfd . "bc", $char_a_ring_nfd, $char_a_ring_nfd . "bc"), array("a" . $char_a_ring_nfd . "bc", $char_a_ring_nfd, $char_a_ring_nfd . "bc"), array("abc", $char_a_ring_nfd, "false"), array($char_a_ring_nfd . "bc", "a", "false"), array("abc", "d", "false"), array("abc", "c", "c"), array("abc", "b", "bc"), array("abc", "a", "abc"), array("abc", "ab", "abc"), array("abc", "abc", "abc"), array("abc", "bc", "bc"), array("abc", "a", FALSE, "abc"), array("abc", "a", TRUE, ""), array("abc", "b", TRUE, "a"), array("abc", "c", TRUE, "ab"), array("ababc", "bab", TRUE, "a"), array("ababc", "abc", TRUE, "ab"), array("ababc", "abc", FALSE, "abc"), array("ab" . $char_a_ring_nfd . "c", "d", "false"), array("bc" . $char_a_ring_nfd . "a", "a", "a"), array("a" . $char_a_ring_nfd . "bc", "b", "bc"), array($char_a_ring_nfd . "bc", "a", "false"), array($char_a_ring_nfd . "abc", "ab", "abc"), array("abc" . $char_a_ring_nfd, "abc", "abc" . $char_a_ring_nfd), array("a" . $char_a_ring_nfd . "bc", $char_a_ring_nfd . "bc", $char_a_ring_nfd . "bc"), array("a" . $char_a_ring_nfd . "bc", $char_a_ring_nfd, FALSE, $char_a_ring_nfd . "bc"), array("a" . $char_a_ring_nfd . "bc", "a", TRUE, ""), array($char_a_ring_nfd . "abc", "b", TRUE, $char_a_ring_nfd . "a"), array("ab" . $char_a_ring_nfd . "c", "c", TRUE, "ab" . $char_a_ring_nfd), array("aba" . $char_a_ring_nfd . "bc", "ba" . $char_a_ring_nfd . "b", TRUE, "a"), array("ababc" . $char_a_ring_nfd, "abc" . $char_a_ring_nfd, TRUE, "ab"), array("abab" . $char_a_ring_nfd . "c", "ab" . $char_a_ring_nfd . "c", FALSE, "ab" . $char_a_ring_nfd . "c"));
    foreach ($tests as $test) {
        $arg1 = urlencode($test[1]);
        $arg0 = urlencode($test[0]);
        $res_str .= "find \"{$arg1}\" in \"{$arg0}\" - grapheme_strstr";
        if (3 == count($test)) {
            $result = grapheme_strstr($test[0], $test[1]);
        } else {
            $res_str .= " before flag is " . ($test[2] ? "TRUE" : "FALSE");
            $result = grapheme_strstr($test[0], $test[1], $test[2]);
        }
        $res_str .= " = ";
        if ($result === false) {
            $res_str .= 'false';
        } else {
            $res_str .= urlencode($result);
        }
        $res_str .= " == " . urlencode($test[count($test) - 1]) . check_result($result, $test[count($test) - 1]) . "\n";
    }
    //=====================================================================================
    $res_str .= "\n" . 'function grapheme_stristr($haystack, $needle, $before_needle = FALSE) {}' . "\n\n";
    $tests = array(array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd, $char_O_diaeresis_nfd, $char_o_diaeresis_nfd), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "O", "o", "O"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd, "o", "false"), array($char_o_diaeresis_nfd . "a" . $char_a_ring_nfd . "bc", $char_a_ring_nfd, $char_a_ring_nfd . "bc"), array("a" . $char_a_ring_nfd . "bc", $char_A_ring_nfd, $char_a_ring_nfd . "bc"), array("abc", $char_a_ring_nfd, "false"), array($char_a_ring_nfd . "bc", "A", "false"), array("abc", "d", "false"), array("abc", "C", "c"), array("aBc", "b", "Bc"), array("abc", "A", "abc"), array("abC", "ab", "abC"), array("abc", "aBc", "abc"), array("abC", "bc", "bC"), array("abc", "A", FALSE, "abc"), array("abc", "a", TRUE, ""), array("aBc", "b", TRUE, "a"), array("abc", "C", TRUE, "ab"), array("aBabc", "bab", TRUE, "a"), array("ababc", "aBc", TRUE, "ab"), array("ababc", "abC", FALSE, "abc"), array("ab" . $char_a_ring_nfd . "c", "d", "false"), array("bc" . $char_a_ring_nfd . "A", "a", "A"), array("a" . $char_a_ring_nfd . "bc", "B", "bc"), array($char_A_ring_nfd . "bc", "a", "false"), array($char_a_ring_nfd . "abc", "Ab", "abc"), array("abc" . $char_A_ring_nfd, "abc", "abc" . $char_A_ring_nfd), array("a" . $char_a_ring_nfd . "bc", $char_A_ring_nfd . "bc", $char_a_ring_nfd . "bc"), array("a" . $char_A_ring_nfd . "bc", $char_a_ring_nfd, FALSE, $char_A_ring_nfd . "bc"), array("a" . $char_a_ring_nfd . "bc", "A", TRUE, ""), array($char_a_ring_nfd . "aBc", "b", TRUE, $char_a_ring_nfd . "a"), array("ab" . $char_a_ring_nfd . "c", "C", TRUE, "ab" . $char_a_ring_nfd), array("aba" . $char_A_ring_nfd . "bc", "ba" . $char_a_ring_nfd . "b", TRUE, "a"), array("ababc" . $char_a_ring_nfd, "aBc" . $char_A_ring_nfd, TRUE, "ab"), array("abAB" . $char_A_ring_nfd . "c", "ab" . $char_a_ring_nfd . "c", FALSE, "AB" . $char_A_ring_nfd . "c"));
    foreach ($tests as $test) {
        $arg1 = urlencode($test[1]);
        $arg0 = urlencode($test[0]);
        $res_str .= "find \"{$arg1}\" in \"{$arg0}\" - grapheme_stristr";
        if (3 == count($test)) {
            $result = grapheme_stristr($test[0], $test[1]);
        } else {
            $res_str .= " before flag is " . ($test[2] ? "TRUE" : "FALSE");
            $result = grapheme_stristr($test[0], $test[1], $test[2]);
        }
        $res_str .= " = ";
        if ($result === false) {
            $res_str .= 'false';
        } else {
            $res_str .= urlencode($result);
        }
        $res_str .= " == " . urlencode($test[count($test) - 1]) . check_result($result, $test[count($test) - 1]) . "\n";
    }
    //=====================================================================================
    $res_str .= "\n" . 'function grapheme_extract($haystack, $size, $extract_type = GRAPHEME_EXTR_COUNT, $start = 0[, $next])' . "\n\n";
    $tests = array(array("abc", 3, "abc"), array("abc", 2, "ab"), array("abc", 1, "a"), array("abc", 0, ""), array("abc", 1, 0, "a"), array("abc", 1, 1, "b"), array("abc", 1, 2, "c"), array("abc", 0, 2, ""), array("abc", 3, 0, 3, "abc"), array("abc", 2, 0, 2, "ab"), array("abc", 1, 0, 1, "a"), array("abc", 0, 0, 0, ""), array("abc", 1, 0, 1, "a"), array("abc", 1, 1, 2, "b"), array("abc", 1, 2, 3, "c"), array("abc", 0, 2, 2, ""), array("http://news.bbc.co.uk/2/hi/middle_east/7831588.stm", 48, 48, 50, "tm"), array($char_a_ring_nfd . "bc", 3, $char_a_ring_nfd . "bc"), array($char_a_ring_nfd . "bc", 2, $char_a_ring_nfd . "b"), array($char_a_ring_nfd . "bc", 1, $char_a_ring_nfd . ""), array($char_a_ring_nfd . "bc", 3, 0, 5, $char_a_ring_nfd . "bc"), array($char_a_ring_nfd . "bc", 2, 0, 4, $char_a_ring_nfd . "b"), array($char_a_ring_nfd . "bc", 1, 0, 3, $char_a_ring_nfd . ""), array($char_a_ring_nfd . "bcde", 2, 3, 5, "bc"), array($char_a_ring_nfd . "bcde", 2, 4, 6, "cd"), array($char_a_ring_nfd . "bcde" . $char_a_ring_nfd . "f", 4, 5, 11, "de" . $char_a_ring_nfd . "f"), array($char_a_ring_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 3, $char_a_ring_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd), array($char_a_ring_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 2, $char_a_ring_nfd . $char_o_diaeresis_nfd), array($char_a_ring_nfd . $char_o_diaeresis_nfd . "c", 1, $char_a_ring_nfd . ""), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 1, 0, $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 1, 2, $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 1, 3, $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 1, 4, $char_diaeresis), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 2, 0, $char_o_diaeresis_nfd . $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 2, 2, $char_o_diaeresis_nfd . $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 2, 3, $char_o_diaeresis_nfd . $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 2, 4, $char_diaeresis . $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 2, 7, $char_diaeresis . $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 2, 8, $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 2, 10, $char_diaeresis), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 2, 11, "false"));
    $next = -1;
    foreach ($tests as $test) {
        $arg0 = urlencode($test[0]);
        $res_str .= "extract from \"{$arg0}\" \"{$test['1']}\" graphemes - grapheme_extract";
        if (3 == count($test)) {
            $result = grapheme_extract($test[0], $test[1]);
        } elseif (4 == count($test)) {
            $res_str .= " starting at byte position {$test['2']}";
            $result = grapheme_extract($test[0], $test[1], GRAPHEME_EXTR_COUNT, $test[2]);
        } else {
            $res_str .= " starting at byte position {$test['2']} with \$next";
            $result = grapheme_extract($test[0], $test[1], GRAPHEME_EXTR_COUNT, $test[2], $next);
        }
        $res_str .= " = ";
        if ($result === false) {
            $res_str .= 'false';
        } else {
            $res_str .= urlencode($result);
        }
        $res_str .= " == " . urlencode($test[count($test) - 1]) . check_result($result, $test[count($test) - 1]);
        if (5 == count($test)) {
            $res_str .= " \$next={$next} == {$test['3']} ";
            if ($next != $test[3]) {
                $res_str .= "***FAILED***";
            }
        }
        $res_str .= "\n";
    }
    //=====================================================================================
    $res_str .= "\n" . 'function grapheme_extract($haystack, $size, $extract_type = GRAPHEME_EXTR_MAXBYTES, $start = 0)' . "\n\n";
    $tests = array(array("abc", 3, "abc"), array("abc", 2, "ab"), array("abc", 1, "a"), array("abc", 0, ""), array($char_a_ring_nfd . "bc", 5, $char_a_ring_nfd . "bc"), array($char_a_ring_nfd . "bc", 4, $char_a_ring_nfd . "b"), array($char_a_ring_nfd . "bc", 1, ""), array($char_a_ring_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 9, $char_a_ring_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd), array($char_a_ring_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 10, $char_a_ring_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd), array($char_a_ring_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 11, $char_a_ring_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd), array($char_a_ring_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 6, $char_a_ring_nfd . $char_o_diaeresis_nfd), array($char_a_ring_nfd . $char_o_diaeresis_nfd . "c", 3, $char_a_ring_nfd . ""), array($char_a_ring_nfd . $char_o_diaeresis_nfd . "c", 4, $char_a_ring_nfd . ""), array($char_a_ring_nfd . $char_o_diaeresis_nfd . "c", 5, $char_a_ring_nfd . ""), array($char_a_ring_nfd . $char_o_diaeresis_nfd . "c", 6, $char_a_ring_nfd . $char_o_diaeresis_nfd), array($char_a_ring_nfd . $char_o_diaeresis_nfd . "c", 7, $char_a_ring_nfd . $char_o_diaeresis_nfd . "c"), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 3, 0, $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 3, 2, $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 3, 3, $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 3, 4, $char_diaeresis), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 6, 0, $char_o_diaeresis_nfd . $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 6, 2, $char_o_diaeresis_nfd . $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 6, 3, $char_o_diaeresis_nfd . $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 5, 4, $char_diaeresis . $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 5, 7, $char_diaeresis . $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 3, 8, $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 2, 10, $char_diaeresis), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 2, 11, "false"));
    foreach ($tests as $test) {
        $arg0 = urlencode($test[0]);
        $res_str .= "extract from \"{$arg0}\" \"{$test['1']}\" graphemes - grapheme_extract GRAPHEME_EXTR_MAXBYTES";
        if (3 == count($test)) {
            $result = grapheme_extract($test[0], $test[1], GRAPHEME_EXTR_MAXBYTES);
        } else {
            $res_str .= " starting at byte position {$test['2']}";
            $result = grapheme_extract($test[0], $test[1], GRAPHEME_EXTR_MAXBYTES, $test[2]);
        }
        $res_str .= " = ";
        if ($result === false) {
            $res_str .= 'false';
        } else {
            $res_str .= urlencode($result);
        }
        $res_str .= " == " . urlencode($test[count($test) - 1]) . check_result($result, $test[count($test) - 1]) . "\n";
    }
    //=====================================================================================
    $res_str .= "\n" . 'function grapheme_extract($haystack, $size, $extract_type = GRAPHEME_EXTR_MAXCHARS, $start = 0)' . "\n\n";
    $tests = array(array("abc", 3, "abc"), array("abc", 2, "ab"), array("abc", 1, "a"), array("abc", 0, ""), array("abc" . $char_o_diaeresis_nfd, 0, ""), array("abc" . $char_o_diaeresis_nfd, 1, "a"), array("abc" . $char_o_diaeresis_nfd, 2, "ab"), array("abc" . $char_o_diaeresis_nfd, 3, "abc"), array("abc" . $char_o_diaeresis_nfd, 4, "abc"), array("abc" . $char_o_diaeresis_nfd, 5, "abc" . $char_o_diaeresis_nfd), array("abc" . $char_o_diaeresis_nfd, 6, "abc" . $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . "abc", 0, ""), array($char_o_diaeresis_nfd . "abc", 1, ""), array($char_o_diaeresis_nfd . "abc", 2, $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . "abc", 3, $char_o_diaeresis_nfd . "a"), array($char_o_diaeresis_nfd . "abc", 4, $char_o_diaeresis_nfd . "ab"), array($char_o_diaeresis_nfd . "abc" . $char_a_ring_nfd . "xyz", 5, $char_o_diaeresis_nfd . "abc"), array($char_o_diaeresis_nfd . "abc" . $char_a_ring_nfd . "xyz", 6, $char_o_diaeresis_nfd . "abc"), array($char_o_diaeresis_nfd . "abc" . $char_a_ring_nfd . "xyz", 7, $char_o_diaeresis_nfd . "abc" . $char_a_ring_nfd), array($char_o_diaeresis_nfd . "abc" . $char_a_ring_nfd . "xyz", 8, $char_o_diaeresis_nfd . "abc" . $char_a_ring_nfd . "x"), array("abc", 3, 0, "abc"), array("abc", 2, 1, "bc"), array("abc", 1, 2, "c"), array("abc", 0, 3, "false"), array("abc", 1, 3, "false"), array("abc", 1, 999, "false"), array($char_o_diaeresis_nfd . "abc", 1, 6, "false"), array($char_o_diaeresis_nfd . "abc", 1, 999, "false"), array($char_o_diaeresis_nfd . "abc" . $char_a_ring_nfd . "xyz", 8, 0, $char_o_diaeresis_nfd . "abc" . $char_a_ring_nfd . "x"), array($char_o_diaeresis_nfd . "abc" . $char_a_ring_nfd . "xyz", 8, 1, $char_diaeresis . "abc" . $char_a_ring_nfd . "xy"), array($char_o_diaeresis_nfd . "abc" . $char_a_ring_nfd . "xyz", 8, 2, "abc" . $char_a_ring_nfd . "xyz"), array($char_o_diaeresis_nfd . "abc" . $char_a_ring_nfd . "xyz", 8, 3, "abc" . $char_a_ring_nfd . "xyz"), array($char_o_diaeresis_nfd . "abc" . $char_a_ring_nfd . "xyz", 8, 4, "bc" . $char_a_ring_nfd . "xyz"), array($char_o_diaeresis_nfd . "abc" . $char_a_ring_nfd . "xyz", 8, 5, "c" . $char_a_ring_nfd . "xyz"), array($char_o_diaeresis_nfd . "abc" . $char_a_ring_nfd . "xyz", 8, 6, $char_a_ring_nfd . "xyz"));
    foreach ($tests as $test) {
        $arg0 = urlencode($test[0]);
        $res_str .= "extract from \"{$arg0}\" \"{$test['1']}\" graphemes - grapheme_extract GRAPHEME_EXTR_MAXCHARS";
        if (3 == count($test)) {
            $result = grapheme_extract($test[0], $test[1], GRAPHEME_EXTR_MAXCHARS);
        } else {
            $res_str .= " starting at byte position {$test['2']}";
            $result = grapheme_extract($test[0], $test[1], GRAPHEME_EXTR_MAXCHARS, $test[2]);
        }
        $res_str .= " = ";
        if ($result === false) {
            $res_str .= 'false';
        } else {
            $res_str .= urlencode($result);
        }
        $res_str .= " == " . urlencode($test[count($test) - 1]) . check_result($result, $test[count($test) - 1]) . "\n";
    }
    //=====================================================================================
    return $res_str;
}
Example #9
0
function tb($range, $min_ticks)
{
    global $p, $n_tests, $n_pass, $n_fail;
    $n_tests++;
    $result = $p->test_CalcStepBinary($range, $min_ticks);
    report('Binary', $range, $min_ticks, $result);
    $err = check_result('binary', $min_ticks, $range, $result);
    if (empty($err)) {
        $n_pass++;
    } else {
        $n_fail++;
        echo $err;
    }
}