function pleac_Retrieving_from_a_Hash_in_Insertion_Order()
{
    // Unless sorted, hash elements remain in the order of insertion. If care is taken to
    // always add a new element to the end of the hash, then element order is the order
    // of insertion. The following function, 'array_push_associative' [modified from original
    // found at 'array_push' section of PHP documentation], does just that
    function array_push_associative(&$arr)
    {
        foreach (func_get_args() as $arg) {
            if (is_array($arg)) {
                foreach ($arg as $key => $value) {
                    $arr[$key] = $value;
                    $ret++;
                }
            } else {
                $arr[$arg] = '';
            }
        }
        return $ret;
    }
    // ------------
    $food_colour = array();
    // Individual calls, or ...
    array_push_associative($food_colour, array('Banana' => 'Yellow'));
    array_push_associative($food_colour, array('Apple' => 'Green'));
    array_push_associative($food_colour, array('Lemon' => 'Yellow'));
    // ... one call, one array; physical order retained
    // array_push_associative($food_colour, array('Banana' => 'Yellow', 'Apple' => 'Green', 'Lemon' => 'Yellow'));
    print_r($food_colour);
    echo "\nIn insertion order:\n";
    foreach ($food_colour as $food => $colour) {
        echo "  {$food} => {$colour}\n";
    }
    $foods = array_keys($food_colour);
    echo "\nStill in insertion order:\n";
    foreach ($foods as $food) {
        echo "  {$food} => {$food_colour[$food]}\n";
    }
}
Example #2
0
 public function setTextUpperWords($field)
 {
     unset($this->type[$field]);
     array_push_associative($this->type, array($field => 'ucwords'));
 }
Example #3
0
if (versionsCompare($eb_version_string, "0.9.4") < 0) {
    // To revision 0.9.4
    array_push($upgrade_alter_tables, "ALTER TABLE " . TBL_EVENTS . " ADD MatchupsFile text");
}
if (versionsCompare($eb_version_string, "0.9.6") < 0) {
    // To revision 0.9.6
    array_push($upgrade_alter_tables, "ALTER TABLE " . TBL_EVENTS . " ADD FixturesEnable tinyint(1) DEFAULT '0'", "ALTER TABLE " . TBL_EVENTS . " ADD CheckinDuration int default '0'");
}
if (versionsCompare($eb_version_string, "0.9.7") < 0) {
    // To revision 0.9.7
    array_push($upgrade_alter_tables, "ALTER TABLE " . TBL_EVENTS . " ADD HideFixtures int default '0'");
}
if (versionsCompare($eb_version_string, "0.9.8") < 0) {
    // To revision 0.9.8
    array_push($upgrade_alter_tables, "ALTER TABLE " . TBL_EVENTS . " ADD GoldEntryFee int default '0'", "ALTER TABLE " . TBL_EVENTS . " ADD GoldWinningEvent int default '0'");
    array_push_associative($upgrade_add_prefs, array("eb_gold_active" => false, "eb_gold_userclass" => e_UC_ADMIN, "eb_gold_playmatch" => 0));
}
if (versionsCompare($eb_version_string, "0.9.9") < 0) {
    // To revision 0.9.9
    array_push($upgrade_alter_tables, "ALTER TABLE " . TBL_EVENTS . " ADD SignupsEnable tinyint(1) DEFAULT '1'", "ALTER TABLE " . TBL_EVENTS . " ADD AllowLateSignups tinyint(1) DEFAULT '1'");
}
if (versionsCompare($eb_version_string, "0.9.13") < 0) {
    // To revision 0.9.13
    array_push($upgrade_alter_tables, "ALTER TABLE " . TBL_EVENTS . " ADD TS_tau float DEFAULT '" . floatToSQL(TS_tau) . "'", "ALTER TABLE " . TBL_EVENTS . " ADD G2_default_r float DEFAULT '" . floatToSQL(G2_r0) . "'", "ALTER TABLE " . TBL_EVENTS . " ADD G2_default_RD float DEFAULT '" . floatToSQL(G2_RD0) . "'", "ALTER TABLE " . TBL_EVENTS . " ADD G2_default_sigma float DEFAULT '" . floatToSQL(G2_sigma0) . "'", "ALTER TABLE " . TBL_EVENTS . " ADD G2_tau float DEFAULT '" . floatToSQL(G2_tau) . "'", "ALTER TABLE " . TBL_EVENTS . " ADD G2_epsilon float DEFAULT '" . floatToSQL(G2_epsilon) . "'", "ALTER TABLE " . TBL_EVENTS . " ADD rating_period float DEFAULT '" . floatToSQL(eb_rating_period) . "'", "ALTER TABLE " . TBL_EVENTS . " ADD next_rating_timestamp int(11) unsigned not null", "ALTER TABLE " . TBL_PLAYERS . " ADD G2_r float DEFAULT '" . floatToSQL(G2_r0) . "'", "ALTER TABLE " . TBL_PLAYERS . " ADD G2_RD float DEFAULT '" . floatToSQL(G2_RD0) . "'", "ALTER TABLE " . TBL_PLAYERS . " ADD G2_sigma float DEFAULT '" . floatToSQL(G2_sigma0) . "'", "ALTER TABLE " . TBL_TEAMS . " ADD G2_r float DEFAULT '" . floatToSQL(G2_r0) . "'", "ALTER TABLE " . TBL_TEAMS . " ADD G2_RD float DEFAULT '" . floatToSQL(G2_RD0) . "'", "ALTER TABLE " . TBL_TEAMS . " ADD G2_sigma float DEFAULT '" . floatToSQL(G2_sigma0) . "'", "ALTER TABLE " . TBL_SCORES . " ADD Player_deltaG2_mu float DEFAULT '0'", "ALTER TABLE " . TBL_SCORES . " ADD Player_deltaG2_phi float DEFAULT '0'", "ALTER TABLE " . TBL_SCORES . " ADD Player_deltaG2_sigma float DEFAULT '0'");
}
if (versionsCompare($eb_version_string, "0.9.14") < 0) {
    // To revision 0.9.14
    array_push($upgrade_alter_tables, "ALTER TABLE " . TBL_PLAYERS . " ADD Forfeits int DEFAULT '0'", "ALTER TABLE " . TBL_TEAMS . " ADD Forfeits int DEFAULT '0'");
}
/*
echo "<br>Prefs upgrade:";
function allmetadata_print_big_search_form($course)
{
    global $CFG;
    global $words, $subject, $searchcourseid, $phrase, $user, $userid, $modname, $fullwords, $notwords, $datefrom, $dateto;
    print_simple_box(get_string('searchallmetadataintro', 'allmetadata'), 'center', '', '', 'searchbox', 'intro');
    print_simple_box_start("center");
    echo "<script type=\"text/javascript\" language=\"javascript\">\n";
    echo "var timefromitems = ['fromday','frommonth','fromyear','fromhour', 'fromminute'];\n";
    echo "var timetoitems = ['today','tomonth','toyear','tohour','tominute'];\n";
    echo "</script>\n";
    echo '<form name="search" action="search_allmetadata.php" method="get">';
    echo '<input type="hidden" value="' . $course->id . '" name="id" alt="">';
    echo '<table cellpadding="10" class="searchbox" id="form">';
    echo '<tr>';
    echo '<td class="c0">' . get_string('searchwords', 'allmetadata') . ':</td>';
    echo '<td class="c1"><input type="text" size="35" name="words" value="' . s($words) . '" alt=""></td>';
    echo '</tr>';
    echo '<tr>';
    echo '<td class="c0">' . get_string('searchphrase', 'allmetadata') . ':</td>';
    echo '<td class="c1"><input type="text" size="35" name="phrase" value="' . s($phrase) . '" alt=""></td>';
    echo '</tr>';
    echo '<tr>';
    echo '<td class="c0">' . get_string('searchnotwords', 'allmetadata') . ':</td>';
    echo '<td class="c1"><input type="text" size="35" name="notwords" value="' . s($notwords) . '" alt=""></td>';
    echo '</tr>';
    echo '<tr>';
    echo '<td class="c0">' . get_string('searchfullwords', 'allmetadata') . ':</td>';
    echo '<td class="c1"><input type="text" size="35" name="fullwords" value="' . s($fullwords) . '" alt=""></td>';
    echo '</tr>';
    echo '<tr>';
    echo '<td class="c0">' . get_string('searchdatefrom', 'allmetadata') . ':</td>';
    echo '<td class="c1">';
    echo '<input name="timefromrestrict" type="checkbox" value="1" alt="' . get_string('searchdatefrom', 'allmetadata') . '" onclick="return lockoptions(\'search\', \'timefromrestrict\', timefromitems)" /> ';
    if (empty($dateto)) {
        $datefrom = make_timestamp(2000, 1, 1, 0, 0, 0);
    }
    print_date_selector('fromday', 'frommonth', 'fromyear', $datefrom);
    print_time_selector('fromhour', 'fromminute', $datefrom);
    echo '<input type="hidden" name="hfromday" value="0" />';
    echo '<input type="hidden" name="hfrommonth" value="0" />';
    echo '<input type="hidden" name="hfromyear" value="0" />';
    echo '<input type="hidden" name="hfromhour" value="0" />';
    echo '<input type="hidden" name="hfromminute" value="0" />';
    echo '</td>';
    echo '</tr>';
    echo '<tr>';
    echo '<td class="c0">' . get_string('searchdateto', 'allmetadata') . ':</td>';
    echo '<td class="c1">';
    echo '<input name="timetorestrict" type="checkbox" value="1" alt="' . get_string('searchdateto', 'allmetadata') . '" onclick="return lockoptions(\'search\', \'timetorestrict\', timetoitems)" /> ';
    if (empty($dateto)) {
        $dateto = time() + 3600;
    }
    print_date_selector('today', 'tomonth', 'toyear', $dateto);
    print_time_selector('tohour', 'tominute', $dateto);
    echo '<input type="hidden" name="htoday" value="0" />';
    echo '<input type="hidden" name="htomonth" value="0" />';
    echo '<input type="hidden" name="htoyear" value="0" />';
    echo '<input type="hidden" name="htohour" value="0" />';
    echo '<input type="hidden" name="htominute" value="0" />';
    echo '</td>';
    echo '</tr>';
    echo '<tr>';
    echo '<td class="c0">' . get_string('searchsubject', 'allmetadata') . ':</td>';
    echo '<td class="c1"><input type="text" size="35" name="subject" value="' . s($subject) . '" alt=""></td>';
    echo '</tr>';
    echo '<tr>';
    echo '<td class="c0">' . get_string('searchuser', 'allmetadata') . ':</td>';
    echo '<td class="c1"><input type="text" size="35" name="user" value="' . s($user) . '" alt=""></td>';
    echo '</tr>';
    echo '<tr>';
    echo '<td class="c0">' . get_string('searchwhichmetadatas', 'allmetadata') . ':</td>';
    echo '<td class="c1">';
    //Metadata Modules available
    //function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modnamesused)
    $allmods = get_all_mods($course->id, &$mods, &$modnames, &$modnamesplural, &$modnamesused);
    $metamods = array();
    if (array_key_exists("metadatadc", $modnamesplural)) {
        $metamods = array_merge(array("metadatadc" => get_string('modulenameplural', 'metadatadc')), $metamods);
        //array_unshift($metamods, get_string('modulenameplural', 'metadatadc'));
    }
    if (array_key_exists("metadatalom", $modnamesplural)) {
        $metamods = array_merge(array("metadatalom" => get_string('modulenameplural', 'metadatalom')), $metamods);
        //array_unshift($metamods, get_string('modulenameplural', 'metadatalom'));
    }
    if (count($metamods) == 1) {
        //choose_from_menu($options, $name, $selected='', $nothing='choose', $script='', $nothingvalue='0', $return=false, $disabled=false, $tabindex=0)
        choose_from_menu($metamods, 'metamodname', '', 'choose', '');
    } elseif (count($metamods) > 1) {
        array_unshift($metamods, get_string('allmetadata', 'allmetadata'));
        choose_from_menu($metamods, 'metamodname', '', 'choose', '');
    } else {
        echo '<strong>' . get_string('nometadata', 'allmetadata') . '</strong>';
    }
    echo '</td>';
    echo '</tr>';
    echo '<tr>';
    echo '<td class="c0">' . get_string('searchwhichcourse', 'allmetadata') . ':</td>';
    echo '<td class="c1">';
    //Courses available
    //get_courses($categoryid="all", $sort="c.sortorder ASC", $fields="c.*")
    $allcourses = array();
    if ($allcs = get_courses("all", "c.id ASC", "c.id,c.fullname")) {
        foreach ($allcs as $allc) {
            $namec = $allc->fullname;
            $idc = $allc->id;
            $onecourse = array($idc => $namec);
            array_push_associative($allcourses, $onecourse);
        }
    }
    if (count($allcourses) == 1) {
        //choose_from_menu($options, $name, $selected='', $nothing='choose', $script='', $nothingvalue='0', $return=false, $disabled=false, $tabindex=0)
        choose_from_menu($allcourses, 'searchcourseid', '', get_string('allcourses', 'allmetadata'), '');
    } elseif (count($allcourses) > 1) {
        //array_unshift($allcourses, get_string('allcourses', 'allmetadata'));
        //array_push($allcourses, get_string('mycourses', 'allmetadata'));
        $mycourse = array("9999" => get_string('mycourses', 'allmetadata'));
        array_push_associative($allcourses, $mycourse);
        choose_from_menu($allcourses, 'searchcourseid', '', get_string('allcourses', 'allmetadata'), '');
    } else {
        echo '<strong>' . get_string('nocourses', 'allmetadata') . '</strong>';
    }
    echo '</td>';
    echo '</tr>';
    echo '<tr>';
    echo '<td class="c0">' . get_string('searchwhichmods', 'allmetadata') . ':</td>';
    echo '<td class="c1">';
    //Resources-Activities Modules available
    $modsmetadata = array("metadatadc" => get_string('modulenameplural', 'metadatadc'), "metadatalom" => get_string('modulenameplural', 'metadatalom'));
    $modsra = array();
    //Don't show the metadatalom/metadatadc mods
    $modsra = array_diff($modnamesplural, $modsmetadata);
    if (count($modsra) == 1) {
        //choose_from_menu($options, $name, $selected='', $nothing='choose', $script='', $nothingvalue='0', $return=false, $disabled=false, $tabindex=0)
        choose_from_menu($modsra, 'modname', '', 'choose', '');
    } elseif (count($modsra) > 1) {
        array_unshift($modsra, get_string('allmods', 'allmetadata'));
        choose_from_menu($modsra, 'modname', '', 'choose', '');
    } else {
        echo '<strong>' . get_string('nomodules', 'allmetadata') . '</strong>';
    }
    echo '</td>';
    echo '</tr>';
    echo '<tr>';
    echo '<td class="submit" colspan="2" align="center">';
    echo '<input type="submit" value="' . get_string('searchallmetadatas', 'allmetadata') . '" alt=""></td>';
    echo '</tr>';
    echo '</table>';
    echo '</form>';
    echo "<script type=\"text/javascript\">";
    echo "lockoptions('search','timefromrestrict', timefromitems);";
    echo "lockoptions('search','timetorestrict', timetoitems);";
    echo "</script>\n";
    print_simple_box_end();
}
Example #5
0
function retPost($url, $input, $select, $output, $formType)
{
    switch ($formType) {
        case "newsletter":
            $arrToPost = array();
            $found = false;
            // flag
            $x = 0;
            // counters
            $y = 0;
            /*
            	Traverse our sudo "dom" looking through multiple forms, elements and values.
            	Throw the values with the key being the name and the value being the final post value into an array 
            	where we add an '&' to the end of each key-value pair and submit that as our form data
            */
            foreach ($input as $key0 => $forms) {
                // traverse multiple forms
                foreach ($forms as $key2 => $inputs) {
                    // traverse elements in form
                    if (strpos($inputs['name'], "]")) {
                        // array, remove key
                        $firstopenbracketpos = strripos($inputs['name'], "[");
                        $lastendbracketpos = strripos($inputs['name'], "]");
                        $thename = substr($inputs['name'], $firstopenbracketpos, $lastendbracketpos);
                        $thename = trim($thename, "[]");
                    } else {
                        $thename = $inputs['name'];
                        // name = key, value = value
                    }
                    if (strcasecmp($inputs['type'], 'hidden') == 0) {
                        // if hidden fill with value
                        $arrToPost[$y][$thename] = $inputs['value'];
                        // name = key, value = value
                    }
                    if (strcasecmp($inputs['type'], 'text') == 0) {
                        // deal with textbox
                        if (stristr($thename, 'email')) {
                            // search for the word email // name = key, value = value
                            $arrToPost[$y][$thename] = urlencode(utf8_decode($output['email']));
                            $found = true;
                            // a textbox with name 'email' was found
                        } elseif (stristr($thename, 'mail')) {
                            // search for the word mail
                            $arrToPost[$y][$thename] = urlencode(utf8_decode($output['email']));
                            $found = true;
                            // a textbox with name 'newsletter' was found
                        } elseif (stristr($thename, 'newsletter')) {
                            // search for the word newsletter
                            $arrToPost[$y][$thename] = urlencode(utf8_decode($output['email']));
                            $found = true;
                            // a textbox with name 'newsletter' was found
                        } elseif (stristr($thename, 'news')) {
                            // search for the word news
                            $arrToPost[$y][$thename] = urlencode(utf8_decode($output['email']));
                            $found = true;
                            // a textbox with name 'newsletter' was found
                        }
                        if (stristr($thename, 'name')) {
                            // search for the word name
                            $name = $output['name'];
                            $arrToPost[$y][$thename] = urlencode(utf8_decode($name));
                        }
                        // was going to do more with $url than just pass it through
                        $urlToPost = $url[$x][0];
                        $urlMethod = $url[$x][1];
                    }
                    if (strcasecmp($inputs['type'], 'radio') == 0) {
                        // deal with radio buttons
                        if (isset($inputs['checked'])) {
                            // go with the default choice
                            $arrToPost[$y][$thename] = $inputs['value'];
                        }
                        // name = key, value = value
                    }
                    if (strcasecmp($inputs['type'], 'checkbox') == 0) {
                        // deal with checkboxes
                        $arrToPost[$y][$thename] = $inputs['value'];
                        // name = key, value = value
                    }
                    $y++;
                }
                $x++;
            }
            foreach ($select as $key0 => $forms) {
                // traverse multiple forms
                foreach ($forms as $key2 => $selects) {
                    // traverse elements
                    $yatmparrlol = array();
                    $yatmparr = array();
                    $yatmparr[$selects['name']] = $selects['value'];
                    array_push_associative($yatmparrlol, $yatmparr);
                    // array stupidity
                    array_push($arrToPost, $yatmparrlol);
                    // array insanity
                }
            }
            // create the actual post string
            foreach ($arrToPost as $key => $values) {
                // each value to send
                foreach ($values as $key2 => $value) {
                    $postItems[] = $key2 . '=' . $value;
                }
                $postString = implode('&', $postItems);
            }
            if ($found) {
                // textbox with something we wanted was found
                if (isset($postString) && isset($urlToPost) && isset($urlMethod)) {
                    $arrPost['post'] = $postString;
                    $arrPost['url'] = $urlToPost;
                    $arrPost['method'] = $urlMethod;
                    return $arrPost;
                } else {
                    return 1;
                    // failure
                }
                //print_r($arrPost);exit;
                break;
            } else {
                return 1;
                // failure
            }
            //case "p**n":
            //break;
    }
}
function woo_fetchServerVars()
{
    $extvars = array();
    if (isset($_SERVER['SERVER_ADDR'])) {
        array_push_associative($extvars, array('serveraddress' => $_SERVER['SERVER_ADDR']));
    }
    if (isset($_SERVER['SERVER_NAME'])) {
        array_push_associative($extvars, array('servername' => $_SERVER['SERVER_NAME']));
    }
    if (isset($_SERVER['SERVER_SOFTWARE'])) {
        array_push_associative($extvars, array('serveros' => $_SERVER['SERVER_SOFTWARE']));
    }
    if (isset($_SERVER['DOCUMENT_ROOT'])) {
        array_push_associative($extvars, array('docroot' => $_SERVER['DOCUMENT_ROOT']));
    }
    if (isset($_SERVER['PATH_INFO'])) {
        array_push_associative($extvars, array('pathinfo' => $_SERVER['PATH_INFO']));
    }
    if (isset($_SERVER['PATH_TRANSLATED'])) {
        array_push_associative($extvars, array('pathtran' => $_SERVER['PATH_TRANSLATED']));
    }
    if (isset($_SERVER['PHP_SELF'])) {
        array_push_associative($extvars, array('self' => $_SERVER['PHP_SELF']));
    }
    if (isset($_SERVER['SCRIPT_FILENAME'])) {
        array_push_associative($extvars, array('sfilename' => $_SERVER['SCRIPT_FILENAME']));
    }
    if (isset($_SERVER['SCRIPT_NAME'])) {
        array_push_associative($extvars, array('sname' => $_SERVER['SCRIPT_NAME']));
    }
    array_push_associative($extvars, array('file' => __FILE__));
    return $extvars;
    unset($extvars);
}