コード例 #1
0
function admin_display($task)
{
    global $db, $cfg;
    if ($task == NULL) {
        $task = 'contests';
    }
    switch ($task) {
        case 'users':
            $table = new HTML_Table();
            $res =& db_query('users_list');
            $res->fetchInto($row);
            // add users table headers
            $headers = array_keys($row);
            array_push($headers, 'groups');
            array_push($headers, 'actions');
            $table->addRow($headers, null, 'TH');
            // add user records
            while ($row) {
                $res2 =& db_query('groups_by_user_id', $row['user_id']);
                // get list of gourps for this user
                $groups = '';
                $res2->fetchInto($row2);
                while ($row2) {
                    $groups .= $row2['name'];
                    if ($res2->fetchInto($row2)) {
                        $groups .= ', ';
                    }
                }
                $res2->free();
                array_push($row, $groups);
                // actions
                array_push($row, "<a href=\"index.php?view=admin&amp;task=edit_user&amp;id={$row['user_id']}\">edit</a>" . ", <a href=\"index.php?view=admin&amp;task=del_user&amp;id={$row['user_id']}\">delete</a>");
                $table->addRow(array_values($row));
                $res->fetchInto($row);
            }
            $res->free();
            $table->altRowAttributes(1, null, array("class" => "altrow"));
            echo '<div class="overflow">' . $table->toHtml() . '</div>';
            break;
        case 'del_user':
            db_query('del_user_by_id', $_GET['id']);
            db_query('del_user_perms_by_id', $_GET['id']);
            redirect('index.php?view=admin&task=users');
            break;
        case 'edit_user':
            // user id to edit given as arg
            $res =& db_query('groups_by_user_id', $_GET['id']);
            // get list of all groups for this user
            $user_groups = array();
            while ($res->fetchInto($row)) {
                array_push($user_groups, $row['group_id']);
            }
            $res->free();
            // get hanndle of user
            $res =& db_query('user_by_id', $_GET['id']);
            $res->fetchInto($row);
            $handle = $row['handle'];
            $res->free();
            $form = new HTML_QuickForm('userForm', 'post', 'index.php?view=admin&task=edit_user&id=' . $_GET['id']);
            $form->addElement('header', null, 'Groups for user ' . $handle . ' (id: ' . $_GET['id'] . ')');
            // get list of all available groups
            $res =& db_query('groups_list');
            // add checkbox for each group
            $groups = array();
            while ($res->fetchInto($row)) {
                $elem =& $form->addElement('checkbox', $row['group_id'], $row['name']);
                if (in_array($row['group_id'], $user_groups)) {
                    $elem->setChecked(true);
                }
                $groups[$row['group_id']] = $row['name'];
            }
            $res->free();
            $form->addElement('submit', 'submit', 'Apply Changes');
            if ($form->validate()) {
                $data = $form->getSubmitValues();
                foreach ($groups as $gid => $name) {
                    $elem =& $form->getElement($gid);
                    if ($data[$gid] == 1) {
                        auth_set_perm($_GET['id'], $gid);
                        $elem->setChecked(true);
                    } else {
                        auth_clear_perm($_GET['id'], $gid);
                        $elem->setChecked(false);
                    }
                }
            }
            $form->display();
            break;
        case 'groups':
            $table = new HTML_Table();
            $res =& db_query('groups_list');
            $res->fetchInto($row);
            // add groups table header
            $headers = array_keys($row);
            array_push($headers, 'views');
            array_push($headers, 'actions');
            $table->addRow($headers, null, 'TH');
            // add group records
            while ($row) {
                $res2 =& db_query('views_by_group_id', $row['group_id']);
                // get list of views allowed for this group
                $views = '';
                $res2->fetchInto($row2);
                while ($row2) {
                    $views .= $row2['view'];
                    if ($res2->fetchInto($row2)) {
                        $views .= ', ';
                    }
                }
                $res2->free();
                array_push($row, $views);
                array_push($row, "<a href=\"index.php?view=admin&amp;task=edit_group&amp;id={$row['group_id']}\">edit</a>" . ", <a href=\"index.php?view=admin&amp;task=del_group&amp;id={$row['group_id']}\">delete</a>");
                $table->addRow(array_values($row));
                $res->fetchInto($row);
            }
            $res->free();
            // decor
            $table->altRowAttributes(1, null, array("class" => "altrow"));
            echo '<div class="overflow">' . $table->toHtml() . '</div>';
            echo "<hr />";
            // form for adding a group
            $form = new HTML_QuickForm('addGroupForm', 'post', 'index.php?view=admin&task=groups');
            $form->addElement('header', null, 'Add a group');
            $form->addElement('text', 'name', 'Name: ');
            $form->addElement('submit', null, 'Submit');
            $form->applyFilter('name', 'trim');
            $form->addRule('name', 'Group name is required.', 'required', null, 'client');
            if ($form->validate()) {
                $res =& $db->autoExecute('groups', $form->getSubmitValues(), DB_AUTOQUERY_INSERT);
                if (PEAR::isError($res)) {
                    error($db->toString());
                }
                redirect('index.php?view=admin&task=groups');
            }
            $form->display();
            break;
        case 'del_group':
            db_query('del_group_by_id', $_GET['id']);
            redirect('index.php?view=admin&task=groups');
            break;
        case 'edit_group':
            // get list of views allowed for this group
            $group_views = array();
            $res =& db_query('views_by_group_id', $_GET['id']);
            while ($res->fetchInto($row)) {
                array_push($group_views, $row['view']);
            }
            $res->free();
            // get name of group
            $res =& db_query('group_by_id', $_GET['id']);
            $res->fetchInto($row);
            $name = $row['name'];
            $res->free();
            $form = new HTML_QuickForm('groupForm', 'post', 'index.php?view=admin&task=edit_group&id=' . $_GET['id']);
            $form->addElement('header', null, 'Views for group ' . $name . ' (id: ' . $_GET['id'] . ')');
            // get list of all available views
            $view_paths = glob($cfg['dir']['views'] . '/*.php');
            $views = array();
            // create the checkboxes, add each view to $views for later checking
            foreach ($view_paths as $path) {
                $tmp = explode('.', basename($path));
                $elem =& $form->addElement('checkbox', $tmp[0], $tmp[0]);
                if (in_array($tmp[0], $group_views)) {
                    $elem->setChecked(true);
                }
                array_push($views, $tmp[0]);
            }
            $form->addElement('submit', 'submit', 'Apply Changes');
            if ($form->validate()) {
                $data = $form->getSubmitValues();
                foreach ($views as $view) {
                    $elem =& $form->getElement($view);
                    if ($data[$view] == 1) {
                        auth_set_view($_GET['id'], $view);
                        $elem->setChecked(true);
                    } else {
                        auth_clear_view($_GET['id'], $view);
                        $elem->setChecked(false);
                    }
                }
            }
            $form->display();
            break;
        case 'views':
            $table = new HTML_Table();
            $table->addRow(array('name', 'path'), null, 'TH');
            // display list of views
            $view_paths = glob($cfg['dir']['views'] . '/*.php');
            foreach ($view_paths as $path) {
                $tmp = explode('.', basename($path));
                $table->addRow(array($tmp[0], $path));
            }
            $table->altRowAttributes(1, null, array("class" => "altrow"));
            echo '<div class="overflow">' . $table->toHtml() . '</div>';
            ?>
<p>To add a view, just drop a .php view-module file inside the views directory.
You can remove a view by deleting or renaming the corresponding file
inside the views directory.
</p> 
		<?php 
            break;
        case 'contests':
            $table = new HTML_Table();
            $res =& db_query('contests_list');
            $res->fetchInto($row);
            if ($row) {
                // add contests table headers
                $headers = array_keys($row);
                array_push($headers, 'actions');
                $table->addRow($headers, null, 'TH');
                // add contests table records
                while ($row) {
                    // Get the handle of the manager for displaying
                    $manager_name = '[none]';
                    $res2 =& $db->query($cfg['sql']['user_by_id'], $row['manager']);
                    if (!PEAR::isError($res2)) {
                        $res2->fetchInto($row2);
                        $manager_name = $row2['handle'];
                        $res2->free();
                    }
                    $row['manager'] = $manager_name;
                    // add edit,delete actions
                    $row['actions'] = "<a href=\"index.php?view=admin&amp;task=edit_contest&amp;id={$row['contest_id']}\">edit</a>, " . "<a href=\"index.php?view=admin&amp;task=del_contest&amp;id={$row['contest_id']}\">delete</a>";
                    $table->addRow(array_values($row));
                    $res->fetchInto($row);
                }
                $res->free();
                // decoration
                $table->altRowAttributes(1, null, array("class" => "altrow"));
                echo '<div class="overflow">' . $table->toHtml() . '</div>';
            } else {
                ?>
<p>No contests added yet.</p>			
			<?php 
            }
            echo "<hr />";
            // get list of all available managers
            $res =& db_query('users_by_group_name', 'Managers');
            while ($res->fetchInto($row)) {
                $managers[$row['user_id']] = $row['handle'];
            }
            // form for adding a contest
            $form = new HTML_QuickForm('contestAddForm', 'post', selflink());
            $form->addElement('header', null, 'Add a contest');
            $form->addElement('text', 'name', 'Name:');
            $form->addElement('text', 'description', 'Description:');
            $elem =& $form->addElement('text', 'team_size', 'Size of team:');
            $form->addElement('select', 'division', 'Division:', $cfg['tcl']['divisions']);
            $elem->setValue('1');
            $date = getdate();
            $form->addElement('date', 'show_time', 'Activation time:', array('format' => 'dMY H:i', 'minYear' => $date['year'], 'maxYear' => $date['year'] + 5));
            $form->addElement('date', 'begin_time', 'Begin time:', array('format' => 'dMY H:i', 'minYear' => $date['year'], 'maxYear' => $date['year'] + 5));
            $form->addElement('date', 'end_time', 'End time:', array('format' => 'dMY H:i', 'minYear' => $date['year'], 'maxYear' => $date['year'] + 5));
            $form->addElement('select', 'manager', 'Contest manager:', $managers);
            $form->addElement('submit', null, 'Submit');
            $form->applyFilter('name', 'trim');
            $form->applyFilter('description', 'trim');
            $form->applyFilter('team_size', 'trim');
            $form->addRule('name', 'Contest name is required.', 'required', null, 'client');
            $form->addRule('manager', 'Contest manager is required.', 'required', null, 'client');
            $form->addRule('team_size', 'Team size is required.', 'required', null, 'client');
            // validate or display form
            if ($form->validate()) {
                $data = $form->getSubmitValues();
                $data['show_time'] = form2sql_datetime($data['show_time']);
                $data['begin_time'] = form2sql_datetime($data['begin_time']);
                $data['end_time'] = form2sql_datetime($data['end_time']);
                $db->autoExecute('contests', $data, DB_AUTOQUERY_INSERT);
                if (PEAR::isError($res)) {
                    error($db->toString());
                }
                redirect('index.php?view=admin&task=contests');
            } else {
                $form->display();
            }
            break;
        case 'del_contest':
            $res =& db_query('del_contest_by_id', $_GET['id']);
            redirect('index.php?view=admin&task=contests');
            break;
        case 'edit_contest':
            // contest to edit given as arg
            $res =& db_query('contest_by_id', $_GET['id']);
            $res->fetchInto($row);
            $res->free();
            // get list of all available managers
            $res =& db_query('users_by_group_name', 'Managers');
            while ($res->fetchInto($row2)) {
                $managers[$row2['user_id']] = $row2['handle'];
            }
            // form for editing the contest
            $form = new HTML_QuickForm('contestEditForm', 'post', selflink());
            $form->addElement('header', null, "Edit contest {$row['name']} (id: {$row['contest_id']})");
            $form->addElement('text', 'name', 'Name:');
            $form->addElement('text', 'description', 'Description:');
            $elem =& $form->addElement('text', 'team_size', 'Size of team:');
            $elem->setValue('1');
            $form->addElement('select', 'division', 'Division:', $cfg['tcl']['divisions']);
            $date = getdate();
            $form->addElement('date', 'show_time', 'Activation time:', array('format' => 'dMY H:i', 'minYear' => $date['year'], 'maxYear' => $date['year'] + 5));
            $form->addElement('date', 'begin_time', 'Begin time:', array('format' => 'dMY H:i', 'minYear' => $date['year'], 'maxYear' => $date['year'] + 5));
            $form->addElement('date', 'end_time', 'End time:', array('format' => 'dMY H:i', 'minYear' => $date['year'], 'maxYear' => $date['year'] + 5));
            $form->addElement('select', 'manager', 'Contest manager:', $managers);
            $form->addElement('text', 'rules', 'Rules URL:');
            $form->addElement('submit', null, 'Submit');
            // convert date format and dtore default values
            $row['show_time'] = sql2form_datetime($row['show_time']);
            $row['begin_time'] = sql2form_datetime($row['begin_time']);
            $row['end_time'] = sql2form_datetime($row['end_time']);
            $form->setDefaults($row);
            $form->applyFilter('name', 'trim');
            $form->applyFilter('description', 'trim');
            $form->applyFilter('team_size', 'trim');
            $form->addRule('name', 'Contest name is required.', 'required', null, 'client');
            $form->addRule('manager', 'Contest manager is required.', 'required', null, 'client');
            $form->addRule('team_size', 'Team size is required.', 'required', null, 'client');
            // validate or display form
            if ($form->validate()) {
                $data = $form->getSubmitValues();
                $data['show_time'] = form2sql_datetime($data['show_time']);
                $data['begin_time'] = form2sql_datetime($data['begin_time']);
                $data['end_time'] = form2sql_datetime($data['end_time']);
                $db->autoExecute('contests', $data, DB_AUTOQUERY_UPDATE, 'contest_id=' . $_GET['id']);
                if (PEAR::isError($res)) {
                    error($db->toString());
                }
                redirect('index.php?view=admin&task=contests');
            } else {
                $form->display();
            }
            break;
        case 'shell':
            $form = new HTML_QuickForm('shellForm', 'post', selflink());
            $field =& $form->addElement('text', 'command', 'Command:');
            $field->setSize(100);
            $ifield =& $form->addElement('textarea', 'input', 'Standard Input:');
            $ifield->setRows(10);
            $ifield->SetCols(80);
            $form->addElement('submit', null, 'Submit');
            $form->display();
            if ($form->validate()) {
                // Write std input file
                $iname = tempnam("/tmp", "in");
                $ifile = fopen($iname, 'w');
                fwrite($ifile, $form->getSubmitValue('input'));
                fclose($ifile);
                $cmd = $form->getSubmitValue('command');
                echo "<pre class=\"shell_output\">";
                echo "<b>\$ " . html_escape($cmd) . "</b>\n";
                exec("{$cmd} 2>&1 < {$iname}", $out, $ret);
                foreach ($out as $line) {
                    echo html_escape($line) . "\n";
                }
                echo "</pre>\n";
                echo "<p>Command returned: {$ret}</p>\n";
            }
            break;
        case 'uploader':
            // Get list of directories to which files can be uploaded
            $dirs = subdir_list('.');
            array_unshift($dirs, './');
            $form = new HTML_QuickForm('uploaderForm', 'post', selflink());
            $form->addElement('header', null, 'Upload a File:');
            $file =& $form->addElement('file', 'file', 'File:');
            $form->addElement('select', 'dir', 'Destination:', $dirs);
            $form->addElement('submit', 'upload', 'Upload');
            $form->addRule('file', 'Please select file to upload.', 'required', null, 'client');
            $form->setMaxFileSize(10485760);
            // try 10 MB max file size
            if ($form->validate()) {
                if ($file->isUploadedFile()) {
                    $dir = $dirs[$form->getSubmitValue('dir')];
                    if ($file->moveUploadedFile($dir)) {
                        echo "<p>File uploaded successfully to {$dir}.</p>";
                    } else {
                        echo "<p>Failed to save uploaded file to {$dir} (insufficient permissions?).</p>";
                    }
                } else {
                    echo "<p>File upload did not finish successfully</p>";
                }
            }
            $form->display();
            echo "<p><b>Note:</b> Any previous file with the same name will be replaced.</p>";
            echo "<hr />";
            $form = new HTML_QuickForm('mkdirForm', 'post', selflink());
            $form->addElement('header', null, 'Create a Directory:');
            $form->addElement('text', 'name', 'Name:');
            $form->addElement('select', 'dir', 'Destination:', $dirs);
            $form->addElement('submit', 'mkdir', 'Mkdir');
            $form->addRule('name', 'Please enter directory name.', 'required', null, 'client');
            if ($form->validate()) {
                $path = $dirs[$form->getSubmitValue('dir')] . '/' . $form->getSubmitValue('name');
                if (file_exists($path)) {
                    echo "<p><b>Warning:</b> File or directory {$path} already exists.</p>";
                } else {
                    if (mkdir($path)) {
                        echo "<p>Directory {$path} created.</p>";
                    } else {
                        echo "<p>Failed to create directory {$path}. Make sure parent directory permissions allow it.</p>";
                    }
                }
            }
            $form->display();
            break;
        case 'phpinfo':
            phpinfo();
            break;
    }
}
コード例 #2
0
function manage_display($task)
{
    global $cfg, $db, $cache;
    if ($task == '') {
        $task = 'status';
    }
    // Verify that the user has management perms for the selected contest
    $res =& db_query('contest_by_id', $_GET['id']);
    $res->fetchInto($row);
    $res->free();
    if ($_SESSION['user_id'] != $row['manager'] && !auth_user_in_group('Administrators')) {
        error("Access denied. You are not the contest-manager for this contest.");
    }
    switch ($task) {
        case 'status':
            $table = new HTML_Table();
            // Re-use $row from above
            if ($row['show_future'] == 1) {
                $status = 'Hidden (not activated yet)';
            } else {
                if ($row['begin_future'] == 1) {
                    $status = 'Not started';
                } else {
                    if ($row['end_future'] == 1) {
                        $status = 'Running';
                    } else {
                        $status = 'Ended';
                    }
                }
            }
            $table->addRow(array('Contest status: ', $status), null, 'TH');
            $table->addRow(array('Name: ', $row['name']));
            $table->addRow(array('Description: ', $row['description']));
            $table->addRow(array('Activation time: ', $row['show_time']));
            $table->addRow(array('Begin time: ', $row['begin_time']));
            $table->addRow(array('End time: ', $row['end_time']));
            if ($row['team_size'] != 1) {
                $table->addRow(array('Max size of team: ', $row['team_size']));
                $prefix = 'Teams';
            } else {
                $table->addRow(array('Individual event: ', 'Yes'));
                $prefix = 'Participants';
            }
            // No. of registered teams
            $res =& db_query('count_teams_by_contest_id', $_GET['id']);
            $res->fetchInto($row);
            $res->free();
            $table->addRow(array($prefix . ' registered: ', $row['count']));
            // No. of teams logged in
            $res =& db_query('count_last_teams_by_contest_id', $_GET['id']);
            $res->fetchInto($row);
            $res->free();
            $table->addRow(array($prefix . ' seen in last 30 minutes: ', $row['count']));
            $table->altRowAttributes(1, null, array("class" => "altrow"));
            echo '<div class="overflow">' . $table->toHtml() . '</div>';
            break;
        case 'problems':
            // display problem info as table
            $table = new HTML_Table();
            $res =& db_query('problems_by_contest_id', $_GET['id']);
            if (!$res->fetchInto($row)) {
                ?>
<p>No problems added yet.</p>			
			<?php 
            } else {
                // extra attributes
                $row['content'] = null;
                $row['actions'] = null;
                $table->addRow(array_keys($row), null, 'TH');
                while ($row) {
                    $row['content'] = "<a href=\"index.php?view=manage&amp;task=show_problem&amp;id={$_GET['id']}&amp;prob_id={$row['prob_id']}\">show</a>";
                    $row['actions'] = "<a href=\"index.php?view=manage&amp;task=edit_problem&amp;id={$_GET['id']}&amp;prob_id={$row['prob_id']}\">edit</a>, " . "<a href=\"index.php?view=manage&amp;task=del_problem&amp;id={$_GET['id']}&amp;prob_id={$row['prob_id']}\">delete</a>";
                    $table->addRow(array_values($row));
                    $res->fetchInto($row);
                }
                $res->free();
                // display tables
                $table->altRowAttributes(1, null, array("class" => "altrow"));
                echo '<div class="overflow">' . $table->toHtml() . '</div>';
            }
            echo "<hr />";
            // form for adding a problem
            $form = new HTML_QuickForm('problemAddForm', 'post', selflink());
            $form->addElement('header', null, 'Add a problem');
            $form->addElement('text', 'prob_id', 'Name (one word ID): ');
            $form->addElement('text', 'summary', 'Summary: ');
            $form->addElement('text', 'weight', 'Points weightage: ');
            $form->addElement('text', 'time_limit', 'Time limit: ');
            $form->addElement('text', 'mem_limit', 'Memory limit: ');
            $elem =& $form->addElement('textarea', 'content', 'Problem content (XML): ');
            $elem->setRows(10);
            $elem->setCols(80);
            $form->addElement('submit', null, 'Submit');
            $form->applyFilter('prob_id', 'trim');
            $form->applyFilter('summary', 'trim');
            $form->applyFilter('weight', 'trim');
            $form->applyFilter('time_limit', 'trim');
            $form->applyFilter('mem_limit', 'trim');
            $form->addRule('prob_id', 'Problem ID is required', 'required', null, 'client');
            $form->addRule('summary', 'Problem summary is required', 'required', null, 'client');
            $form->addRule('weight', 'Points weightage is required', 'required', null, 'client');
            $form->addRule('time_limit', 'Time limit is required', 'required', null, 'client');
            $form->addRule('mem_limit', 'Memory limit is required', 'required', null, 'client');
            $form->addRule('content', 'Problem content in XML is required', 'required', null, 'client');
            if ($form->validate()) {
                $data = $form->getSubmitValues();
                $errs = problem_check($data['content']);
                if ($errs == null) {
                    $data['contest_id'] = $_GET['id'];
                    $res =& $db->autoExecute('problems', $data, DB_AUTOQUERY_INSERT);
                    if (PEAR::isError($res)) {
                        error($res->toString());
                    }
                    $cache->remove(problem_cache_id($_GET['id'], $data['prob_id']) . '.htm');
                    $cache->remove(problem_cache_id($_GET['id'], $data['prob_id']) . '.prob');
                    redirect('index.php?view=manage&task=problems&id=' . $_GET['id']);
                } else {
                    ?>
<p><b>Error:</b> The problem could not be added due to the following errors encountered while
parsing the problem XML file. Please fix them and try submitting again.</p>
				<?php 
                    echo "<ol class=\"errors\">\n";
                    foreach ($errs as $line) {
                        echo "<li>{$line}</li>\n";
                    }
                    echo "</ol>\n<hr />\n";
                }
            }
            $form->display();
            break;
        case 'del_problem':
            db_query('del_problem_by_id', array($_GET['prob_id'], $_GET['id']));
            redirect('index.php?view=manage&task=problems&id=' . $_GET['id']);
            break;
        case 'edit_problem':
            $res =& db_query('problem_by_id', array($_GET['prob_id'], $_GET['id']));
            $res->fetchInto($row);
            $res->free();
            // Get XML content too
            $res =& db_query('problem_content_by_id', array($_GET['prob_id'], $_GET['id']));
            $res->fetchInto($row2);
            $res->free();
            $row['content'] =& $row2['content'];
            // form for editing a problem
            $form = new HTML_QuickForm('problemAddForm', 'post', selflink());
            $form->addElement('header', null, 'Edit a problem');
            $form->addElement('text', 'prob_id', 'Name (one word ID): ');
            $form->addElement('text', 'summary', 'Summary: ');
            $form->addElement('text', 'weight', 'Points weightage: ');
            $form->addElement('text', 'time_limit', 'Time limit: ');
            $form->addElement('text', 'mem_limit', 'Memory limit: ');
            $elem =& $form->addElement('textarea', 'content', 'Problem content (XML): ');
            $elem->setRows(10);
            $elem->setCols(80);
            $form->addElement('submit', null, 'Submit');
            $form->applyFilter('prob_id', 'trim');
            $form->applyFilter('summary', 'trim');
            $form->applyFilter('weight', 'trim');
            $form->applyFilter('time_limit', 'trim');
            $form->applyFilter('mem_limit', 'trim');
            $form->addRule('prob_id', 'Problem ID is required', 'required', null, 'client');
            $form->addRule('summary', 'Problem summary is required', 'required', null, 'client');
            $form->addRule('weight', 'Points weightage is required', 'required', null, 'client');
            $form->addRule('time_limit', 'Time limit is required', 'required', null, 'client');
            $form->addRule('mem_limit', 'Memory limit is required', 'required', null, 'client');
            $form->addRule('content', 'Problem content in XML is required', 'required', null, 'client');
            $form->setDefaults($row);
            if ($form->validate()) {
                $data = $form->getSubmitValues();
                $errs = problem_check($data['content']);
                if ($errs == null) {
                    //$data['contest_id'] = $_GET['id'];
                    $data['version'] = $row['version'] + 1;
                    // increment version
                    $res =& $db->autoExecute('problems', $data, DB_AUTOQUERY_UPDATE, 'contest_id=' . $_GET['id'] . " AND prob_id='" . $data['prob_id'] . "'");
                    if (PEAR::isError($res)) {
                        error($res->toString());
                    }
                    $cache->remove(problem_cache_id($_GET['id'], $data['prob_id']) . '.htm');
                    $cache->remove(problem_cache_id($_GET['id'], $data['prob_id']) . '.prob');
                    redirect('index.php?view=manage&task=problems&id=' . $_GET['id']);
                } else {
                    ?>
<p><b>Error:</b> The changes could not be saved due to the following errors encountered while
parsing the problem XML file. Please fix them and try submitting again.</p>
				<?php 
                    echo "<ol class=\"errors\">\n";
                    foreach ($errs as $line) {
                        echo "<li>{$line}</li>\n";
                    }
                    echo "</ol>\n<hr />\n";
                }
            }
            $form->display();
            break;
        case 'show_problem':
            $res =& db_query('problem_by_id', array($_GET['prob_id'], $_GET['id']));
            $res->fetchInto($problem);
            $res->free();
            problem_display($problem);
            break;
        case 'settings':
            // Re-using $row from above
            // form for editing the contest
            $form = new HTML_QuickForm('contestEditForm', 'post', selflink());
            $form->addElement('header', null, "Edit contest {$row['name']} (id: {$row['contest_id']})");
            $form->addElement('text', 'name', 'Name: ');
            $form->addElement('text', 'description', 'Description: ');
            $elem =& $form->addElement('text', 'team_size', 'Size of team: ');
            $elem->setValue('1');
            $date = getdate();
            $form->addElement('date', 'show_time', 'Activation time: ', array('format' => 'dMY H:i', 'minYear' => $date['year'], 'maxYear' => $date['year'] + 5));
            $form->addElement('date', 'begin_time', 'Begin time: ', array('format' => 'dMY H:i', 'minYear' => $date['year'], 'maxYear' => $date['year'] + 5));
            $form->addElement('date', 'end_time', 'End time: ', array('format' => 'dMY H:i', 'minYear' => $date['year'], 'maxYear' => $date['year'] + 5));
            $form->addElement('text', 'rules', 'Rules URL: ');
            $form->addElement('submit', null, 'Submit');
            // convert date format and store default values
            $row['show_time'] = sql2form_datetime($row['show_time']);
            $row['begin_time'] = sql2form_datetime($row['begin_time']);
            $row['end_time'] = sql2form_datetime($row['end_time']);
            $form->setDefaults($row);
            $form->applyFilter('name', 'trim');
            $form->applyFilter('description', 'trim');
            $form->applyFilter('team_size', 'trim');
            $form->addRule('name', 'Contest name is required.', 'required', null, 'client');
            $form->addRule('team_size', 'Team size is required.', 'required', null, 'client');
            // validate or display form
            if ($form->validate()) {
                $data = $form->getSubmitValues();
                $data['show_time'] = form2sql_datetime($data['show_time']);
                $data['begin_time'] = form2sql_datetime($data['begin_time']);
                $data['end_time'] = form2sql_datetime($data['end_time']);
                $db->autoExecute('contests', $data, DB_AUTOQUERY_UPDATE, 'contest_id=' . $_GET['id']);
                if (PEAR::isError($res)) {
                    error($db->toString());
                }
                redirect('index.php?view=manage&id=' . $_GET['id']);
            } else {
                $form->display();
            }
            break;
        case 'submissions':
            // Re-use $row from above
            if ($row['end_future'] != '1') {
                // Contest has ended, show system test button
                if ($row['tested'] != 1) {
                    ?>
    <p>Contest has ended. 
    <a class="button" href="index.php?view=manage&amp;&amp;task=test&amp;updateratings=false&amp;id=<?php 
                    echo $_GET['id'];
                    ?>
">Test and grade all submissions.</a>
    <a class="button" href="index.php?view=manage&amp;task=test&amp;updateratings=true&amp;id=<?php 
                    echo $_GET['id'];
                    ?>
">Update Ratings</a>

    </p>
                <?php 
                } else {
                    ?>
    <p>Contest has ended and system tests are over.
    <a class="button" href="index.php?view=manage&amp;task=test&amp;id=<?php 
                    echo $_GET['id'];
                    ?>
">Re-run system tests.</a>
    </p>
                <?php 
                }
            }
            // Show table of all solutions in the contest
            $table = new HTML_Table();
            $res =& db_query('solutions_by_contest_id', $_GET['id']);
            if (!$res->fetchInto($row)) {
                // If no solutions in yet
                ?>
<p>Sorry, no solutions have been submitted yet.</p>
			<?php 
            } else {
                $table->addRow(array_keys($row), null, 'TH');
                if ($row['score'] == '') {
                    $row['score'] = 'n/a';
                }
                if ($row['passed'] == '') {
                    $row['passed'] = 'n/a';
                }
                $table->addRow(array_values($row));
                while ($res->fetchInto($row)) {
                    if ($row['score'] == '') {
                        $row['score'] = 'n/a';
                    }
                    if ($row['passed'] == '') {
                        $row['passed'] = 'n/a';
                    }
                    $table->addRow(array_values($row));
                }
                $table->altRowAttributes(1, null, array("class" => "altrow"));
                echo '<div class="overflow">' . $table->toHtml() . '</div>';
            }
            break;
        case 'test':
            require_once 'tester.php';
            ob_end_clean();
            html_reset();
            html_header(null, $cfg["dir"]["themes"] . '/' . $_SESSION["theme"] . '.css', $cfg["dir"]["themes"] . '/' . $_SESSION["theme"] . '-ie.css', null, "submit_frame");
            $contest_id = $_GET['id'];
            $update_ratings = $_GET['updateratings'];
            session_write_close();
            test_contest($update_ratings, $contest_id);
            echo ' <a class="white" href="index.php?view=statistics&amp;task=contest&amp;id=' . $_GET['id'] . '">See the results.</a>';
            html_footer();
            exit;
    }
}
コード例 #3
0
ファイル: ic2_getter.php プロジェクト: xingskycn/p2-php
$_flexy_options =& PEAR5::getStaticProperty('HTML_Template_Flexy', 'options');
$_flexy_options = array('locale' => 'ja', 'charset' => 'Shift_JIS', 'compileDir' => $_conf['compile_dir'] . DIRECTORY_SEPARATOR . 'ic2', 'templateDir' => P2EX_LIB_DIR . '/ImageCache2/templates', 'numberFormat' => '');
$flexy = new HTML_Template_Flexy();
$flexy->setData('php_self', $_SERVER['SCRIPT_NAME']);
$flexy->setData('p2vid', P2_VERSION_ID);
$flexy->setData('skin', $skin_en);
$flexy->setData('isPopUp', $isPopUp);
$flexy->setData('pc', !$_conf['ktai']);
$flexy->setData('iphone', $_conf['iphone']);
$flexy->setData('doctype', $_conf['doctype']);
$flexy->setData('extra_headers', $_conf['extra_headers_ht']);
$flexy->setData('extra_headers_x', $_conf['extra_headers_xht']);
// }}}
// {{{ validate
$execDL = false;
if ($qf->validate() && ($params = $qf->getSubmitValues()) && isset($params['uri']) && isset($params['download'])) {
    $execDL = true;
    $params = array_map('trim', $params);
    // URLを検証
    $purl = @parse_url($params['uri']);
    if (!$purl || !preg_match('/^(https?)$/', $purl['scheme']) || empty($purl['host']) || empty($purl['path'])) {
        P2Util::pushInfoHtml('<p>エラー: 不正なURL</p>');
        $execDL = false;
        $isError = true;
    }
    // プレビューの大きさ
    if (isset($params['preview_size']) && in_array($params['preview_size'], array_keys($_preview_size))) {
        $thumb_type = (int) $params['preview_size'];
    } else {
        $thumb_type = 1;
    }
コード例 #4
0
<table{class}>
<!-- BEGIN label_2 --><tr><th>{label_2}</th><!-- END label_2 -->
<!-- BEGIN label_3 --><th>&nbsp;</th><th>{label_3}</th></tr><!-- END label_3 -->
<tr>
  <td valign="top">{unselected}</td>
  <td align="center">{add}{remove}</td>
  <td valign="top">{selected}</td>
</tr>
</table>
';
$ams->setElementTemplate($template);
if (isset($_POST['fruit'])) {
    $form->setDefaults(array('fruit' => $_POST['fruit']));
}
$form->addElement('submit', 'send', 'Send', array('class' => 'inputCommand'));
$form->addRule('name', 'Your name is required', 'required');
$form->addGroupRule('fruit', 'At least one fruit is required', 'required', null, 1);
$form->applyFilter('__ALL__', 'trim');
$form->applyFilter('__ALL__', 'strip_tags');
$valid = $form->validate();
$tpl = new HTML_Template_Sigma('.');
$tpl->loadTemplateFile('itdynamic.html');
$tpl->setVariable('ams_javascript', $ams->getElementJs(false));
$renderer = new HTML_QuickForm_Renderer_ITDynamic($tpl);
$form->accept($renderer);
if ($valid) {
    $clean = $form->getSubmitValues();
    $msg = sprintf("<p>Welcome <b>%s</b> you've selected these fruits:<br />%s</p>", $clean['name'], implode(', ', $clean['fruit']));
    $tpl->setVariable('message_form_validate', $msg);
}
$tpl->show();
コード例 #5
0
##End of form definition
#
$form->addElement('hidden', 'gopt_id');
$redirect =& $form->addElement('hidden', 'o');
$redirect->setValue($o);
# Smarty template Init
$tpl = new Smarty();
$tpl = initSmartyTpl($path, $tpl);
$form->setDefaults($oreon->optGen);
$subC =& $form->addElement('submit', 'submitC', _("Save"));
$DBRESULT =& $form->addElement('reset', 'reset', _("Reset"));
$valid = false;
if ($form->validate()) {
    # Update in DB
    $ret = array();
    $ret = $form->getSubmitValues();
    updateOption($pearDB, "pdfreports_smtp_server_address", isset($ret["pdfreports_smtp_server_address"]) && $ret["pdfreports_smtp_server_address"] != NULL ? $ret["pdfreports_smtp_server_address"] : "127.0.0.1");
    updateOption($pearDB, "pdfreports_email_sender", isset($ret["pdfreports_email_sender"]) && $ret["pdfreports_email_sender"] != NULL ? $ret["pdfreports_email_sender"] : "*****@*****.**");
    updateOption($pearDB, "pdfreports_report_author", isset($ret["pdfreports_report_author"]) && $ret["pdfreports_report_author"] != NULL ? $ret["pdfreports_report_author"] : "");
    updateOption($pearDB, "pdfreports_report_header_logo", isset($ret["pdfreports_report_header_logo"]) && $ret["pdfreports_report_header_logo"] != NULL ? $ret["pdfreports_report_header_logo"] : "");
    updateOption($pearDB, "pdfreports_path_gen", isset($ret["pdfreports_path_gen"]) && $ret["pdfreports_path_gen"] != NULL ? $ret["pdfreports_path_gen"] : "/usr/local/centreon/www/modules/pdfreports/generatedFiles/");
    # Update in Oreon Object
    $oreon->initOptGen($pearDB);
    $o = NULL;
    $valid = true;
    $form->freeze();
}
if (!$form->validate() && isset($_POST["gopt_id"])) {
    print "<div class='msg' align='center'>" . _("Impossible to validate, one or more field is incorrect") . "</div>";
}
$form->addElement("button", "change", _("Modify"), array("onClick" => "javascript:window.location.href='?p=" . $p . "&o=pdfreports'"));
コード例 #6
0
$form->addElement('header', 'information2', _('Nagvis authentication'));
$form->addElement('text', 'centreon_nagvis_uri', _('Nagvis URI'), $attrsTextLong);
$form->addElement('text', 'centreon_nagvis_path', _('Nagvis Path'), $attrsTextLong);
$form->addElement('select', 'centreon_nagvis_auth', _("Single NagVis user auth or Centreon user auth ? "), array("single" => "Single User", "centreon" => "Centreon User"));
$form->addElement('text', 'centreon_nagvis_single_user', _('Nagvis user name'), $attrsTextLong);
$form->addRule('centreon_nagvis_uri', _('Compulsory field'), 'required');
$form->addRule('centreon_nagvis_path', _('Compulsory field'), 'required');
$form->addRule('centreon_nagvis_auth', _('Compulsory field'), 'required');
$form->addRule('centreon_nagvis_single_user', _('Compulsory field'), 'required');
$form->registerRule('exist', 'callback', 'nagvisInstall');
$form->addRule('centreon_nagvis_path', _('Directory does not exist'), 'exist');
$form->setRequiredNote("<font style='color: red;'>*</font>" . _(" Required fields"));
$form->addElement('submit', 'submitC', _("Save"));
$form->addElement('reset', 'reset', _("Reset"));
if ($form->validate()) {
    $values = $form->getSubmitValues();
    $queryInsert = 'UPDATE `options` SET `value` = "%s" WHERE `key` = "%s"';
    $pearDB->query(sprintf($queryInsert, $pearDB->escape($values['centreon_nagvis_uri']), 'centreon_nagvis_uri'));
    $pearDB->query(sprintf($queryInsert, $pearDB->escape($values['centreon_nagvis_path']), 'centreon_nagvis_path'));
    $pearDB->query(sprintf($queryInsert, $pearDB->escape($values['centreon_nagvis_auth']), 'centreon_nagvis_auth'));
    $pearDB->query(sprintf($queryInsert, $pearDB->escape($values['centreon_nagvis_single_user']), 'centreon_nagvis_single_user'));
}
/*
 * Get options
 */
if (!isset($values)) {
    $values = array();
    $query = 'SELECT `key`, `value` FROM `options` WHERE `key` IN ("centreon_nagvis_uri", "centreon_nagvis_path", "centreon_nagvis_auth", "centreon_nagvis_single_user")';
    $res = $pearDB->query($query);
    if (!PEAR::isError($res)) {
        while ($row = $res->fetchRow()) {
コード例 #7
0
ファイル: iv2.php プロジェクト: xingskycn/p2-php
    $flexy->setData('k_color', array('c_bgcolor' => !empty($_conf['mobile.background_color']) ? $_conf['mobile.background_color'] : '#ffffff', 'c_text' => !empty($_conf['mobile.text_color']) ? $_conf['mobile.text_color'] : '#000000', 'c_link' => !empty($_conf['mobile.link_color']) ? $_conf['mobile.link_color'] : '#0000ff', 'c_vlink' => !empty($_conf['mobile.vlink_color']) ? $_conf['mobile.vlink_color'] : '#9900ff'));
    $flexy->setData('top_url', dirname($_SERVER['SCRIPT_NAME']) . '/index.php');
    $flexy->setData('accesskey', $_conf['accesskey']);
} else {
    $flexy->setData('skin', str_replace('&amp;', '&', $skin_en));
}
$flexy->setData('pc', !$_conf['ktai']);
$flexy->setData('iphone', $_conf['iphone']);
$flexy->setData('doctype', $_conf['doctype']);
$flexy->setData('extra_headers', $_conf['extra_headers_ht']);
$flexy->setData('extra_headers_x', $_conf['extra_headers_xht']);
// }}}
// {{{ validate
// 検証
$qf->validate();
$sv = $qf->getSubmitValues();
$page = ImageCache2_ParameterUtility::getValidValue('page', $_defaults['page'], 'intval');
$cols = ImageCache2_ParameterUtility::getValidValue('cols', $_defaults['cols'], 'intval');
$rows = ImageCache2_ParameterUtility::getValidValue('rows', $_defaults['rows'], 'intval');
$order = ImageCache2_ParameterUtility::getValidValue('order', $_defaults['order']);
$sort = ImageCache2_ParameterUtility::getValidValue('sort', $_defaults['sort']);
$field = ImageCache2_ParameterUtility::getValidValue('field', $_defaults['field']);
$keyword = ImageCache2_ParameterUtility::getValidValue('keyword', $_defaults['keyword']);
$threshold = ImageCache2_ParameterUtility::getValidValue('threshold', $_defaults['threshold'], 'intval');
$compare = ImageCache2_ParameterUtility::getValidValue('compare', $_defaults['compare']);
$mode = ImageCache2_ParameterUtility::getValidValue('mode', $_defaults['mode'], 'intval');
$thumbtype = ImageCache2_ParameterUtility::getValidValue('thumbtype', $_defaults['thumbtype'], 'intval');
// サムネイル作成クラス
$thumbsize = $thumbtype;
if (!empty($_SESSION['device_pixel_ratio'])) {
    $dpr = $_SESSION['device_pixel_ratio'];
コード例 #8
0
function login_display($task)
{
    global $db, $cfg;
    if ($task == NULL) {
        if (auth_logged_in()) {
            $task = 'profile';
        } else {
            $task = 'login';
        }
    }
    switch ($task) {
        case "register":
            $form = new HTML_QuickForm('regForm', 'post', 'index.php?view=login&task=register');
            $form->addElement('header', null, 'Register');
            $form->addElement('text', 'handle', 'Handle:');
            $form->addElement('password', 'password', 'Password:'******'password', 'password2', 'Retype Password:'******'text', 'email', 'Email:');
            $form->addElement('header', null, 'Personal Information');
            $form->addElement('text', 'first_name', 'First Name:');
            $form->addElement('text', 'last_name', 'Last Name:');
            $date = getdate();
            $form->addElement('date', 'birth_date', 'Date of Birth:', array('minYear' => $date['year'] - 100, 'maxYear' => $date['year']));
            $form->addElement('text', 'address', 'Street Address:');
            $form->addElement('text', 'city', 'City:');
            $form->addElement('text', 'state', 'State:');
            $form->addElement('text', 'zip', 'Zip:');
            $form->addElement('select', 'division', 'Division:', $cfg["tcl"]["divisions"]);
            $form->addElement('text', 'phone', 'Phone:');
            $form->addElement('textarea', 'quote', 'Quote:', array('rows' => 3));
            $form->addElement('header', null, 'For Password Recovery');
            $form->addElement('text', 'question', 'Secret Question:');
            $form->addElement('text', 'secret', 'Secret Answer:');
            $form->addElement('submit', null, 'Submit');
            $form->applyFilter('handle', 'trim');
            $form->applyFilter('handle', 'strtolower');
            $form->applyFilter('email', 'trim');
            $form->applyFilter('first_name', 'trim');
            $form->applyFilter('last_name', 'trim');
            $form->applyFilter('address', 'trim');
            $form->applyFilter('state', 'trim');
            $form->applyFilter('city', 'trim');
            $form->applyFilter('zip', 'trim');
            $form->applyFilter('phone', 'trim');
            $form->applyFilter('question', 'trim');
            $form->applyFilter('secret', 'trim');
            $form->addRule('handle', 'Handle is required.', 'required', null, 'client');
            $form->addRule('handle', 'Handle can only contain alphabets, numbers. and/or undescores.', 'alphanumericscore', null, 'client');
            $form->addRule('password', 'Password is required.', 'required', null, 'client');
            $form->addRule('password2', 'Retyped password is required.', 'required', null, 'client');
            $form->addRule('email', 'Email is required.', 'required', null, 'client');
            $form->addRule('division', 'Division is required.', 'required', null, 'client');
            $form->addRule('first_name', 'First name is required.', 'required', null, 'client');
            $form->addRule('last_name', 'Last name is required.', 'required', null, 'client');
            $form->addRule('question', 'Secret question is required.', 'required', null, 'client');
            $form->addRule('secret', 'Secret answer is required.', 'required', null, 'client');
            $form->addRule('handle', 'Login handle must be between 4 and 15 characters.', 'rangelength', array(4, 15), 'client');
            $form->addRule('password', 'Password must be between 6 and 15 characters.', 'rangelength', array(4, 15), 'client');
            $form->addRule('email', 'Email is invalid.', 'email', null, 'client');
            $form->addRule(array('password', 'password2'), 'Passwords much match.', 'compare', null, 'client');
            $show_form = true;
            if ($form->validate()) {
                $data = $form->getSubmitValues();
                unset($data['password2']);
                // Verify that email is unique
                $res =& db_query('user_by_email', $data['email']);
                if ($res->numRows() != 0) {
                    $res->fetchInto($user);
                    $res->free();
                    ?>
				<p><b>Email already registered to an existing user!</b><br />
				User <?php 
                    echo '<b>' . $user['handle'] . '</b>';
                    ?>
 owns that email address. Maybe you've already registered and forgotten about it?
				Try <a href="index.php?view=login&amp;task=login">logging in</a> if that is the case.</p>
				<?php 
                } else {
                    // Format the birth date correctly
                    $data['birth_date'] = form2sql_date($data['birth_date']);
                    $user = auth_register($data);
                    if ($user == null) {
                        $show_form = false;
                        ?>
	<p><strong>Thanks for registering!</strong><br /> Please proceed to <a href="index.php?view=login&amp;task=login">login</a> into your new account.</p>
	<?php 
                    } else {
                        ?>
	<p><b>That user-handle has already been taken!</b><br/> It belongs to an user registered with the name <?php 
                        echo $user['first_name'] . ' ' . $user['last_name'];
                        ?>
. Please try again with another handle.</p>
	<?php 
                    }
                }
            }
            if ($show_form) {
                ?>
<p><strong>Please fill in your details below.</strong><br /> 
Please choose your <strong>handle</strong> and <strong>division</strong> carefully. Once chosen, they cannot be changed. Moreover, choosing an inappropriate division will lead to disqualification.
<br> 
<br>Any doubts and problems should find their way to the <? echo '<a href="mailto:'.$cfg["site"]["email"].'">admins</a>'; ?>.
</p>
<?php 
                $form->display();
            }
            break;
        case 'logout':
            auth_logout();
            redirect('index.php');
            break;
        case 'login':
            $form = new HTML_QuickForm('loginForm', 'post', 'index.php?view=login&task=login');
            $form->addElement('header', null, 'Login');
            $form->addElement('text', 'handle', 'Handle:');
            $form->addElement('password', 'password', 'Password:'******'submit', null, 'Submit');
            $form->applyFilter('handle', 'trim');
            $form->applyFilter('handle', 'strtolower');
            if ($form->validate()) {
                if (auth_login($form->getSubmitValue('handle'), $form->getSubmitValue('password'))) {
                    redirect('index.php');
                } else {
                    echo "<p>Invalid handle or password! Please try again.</p>\n";
                }
            } else {
                $signature = '<i>' . $_SERVER['SERVER_SOFTWARE'] . ' Server at ' . $_SERVER['SERVER_NAME'] . ', port ' . $_SERVER['SERVER_PORT'] . '</i>';
                ?>
<p><strong>Welcome!</strong><br />
Please login to proceed, or <a href="index.php?view=login&amp;task=register">register</a>
 with us if you're new here.</p>
<?php 
            }
            $form->display();
            ?>
<p class="system_info">This is <b>OGS 2</b> running on <? echo $signature ?>.<br />
<b>Server System:</b> <?php 
            system("uname -srmp");
            ?>
</p>
<hr />
<div id="javascript_warn"><p><strong>Warning!</strong> Javascript is not enabled on your browser. Many features will not work without it.</p></div>
<script type="text/javascript">
getObj('javascript_warn').style.display = "none";
</script>
<p><strong>Before you login.</strong> This website makes heavy use of modern web technologies such as CSS
and Javascript, to enjoy which, you'll need a modern browser. Below is a list of browsers along with their
earliest versions which are guaranteed to work with this website. For best results, we recommend a resolution higher than 800x600 with True Color (32-bit).</p>
<table class="browsers">
<tr>
    <td><img width="32" height="32" src="images/firefox-icon.png" /></td>
    <td><img width="32" height="32" src="images/opera_icon.gif" /></td>
    <td><img width="32" height="32" src="images/internet-explorer-icon.png" /></td>
    <td><img width="32" height="32" src="images/mozilla-icon.png" /></td>
    <td><img width="32" height="32" src="images/safari-icon.png" /></td>
    <td><img width="32" height="32" src="images/icon-konqueror.jpg" /></td>
    <td><img width="32" height="32" src="images/netscape-icon.png" /></td>
</tr>
<tr>
    <td><a href="http://www.getfirefox.com/">Firefox</a><br />1.0+</td>
    <td><a href="http://www.opera.com/">Opera</a><br />7+</td>
    <td><a href="http://www.microsoft.com/windows/ie/">Internet<br />Explorer</a> 6.0+<a></a></td>
    <td><a href="http://www.mozilla.org/products/mozilla1.x/">Mozilla</a><br />1.3+</td>
    <td><a href="http://www.apple.com/safari/">Safari</a><br />1.2+</td>
    <td><a href="http://www.konqueror.org/">Konqueror</a><br />3+</td>
    <td><a href="http://browser.netscape.com">Netscape</a><br />6+</td>
</tr>
</table>
<p>If you experience any problems while browsing this website using one of the above browsers,
then you're welcome to <a href="mailto:de.arijit@gmail.com">email the webmaster</a>. We hope you'll
enjoy your stay here.</p>
        <?php 
            break;
        case 'forgot':
            ?>
<p><strong>Lost your password?</strong><br />Follow these steps to generate a new password for your account.
You will be mailed the new password once you're done.</p>
<?php 
            $form1 = new HTML_QuickForm('forgotForm1', 'post', 'index.php?view=login&task=forgot');
            $form1->addElement('header', null, 'Password Recovery: Step 1');
            $form1->addElement('text', 'handle', 'Enter your login handle:');
            $form1->addElement('submit', null, 'Next');
            $form1->applyFilter('handle', 'trim');
            $form1->applyFilter('handle', 'strtolower');
            $form1->addRule('handle', 'Your login handle is required.', 'required', null, 'client');
            if ($form1->validate()) {
                redirect('index.php?view=login&task=forgot2&handle=' . $form1->getSubmitValue('handle'));
            } else {
                $form1->display();
                ?>
<p><strong>Please note:</strong> Due to the lack of emailing support on our server (Yes! We require better servers!), you'll have to wait a few
hours before we can mail you your new password manually.</p> 
<?php 
            }
            break;
        case 'forgot2':
            $res =& db_query('user_by_handle', $_GET['handle']);
            if ($res->numRows() == 0) {
                $res->free();
                ?>
<p>The given login handle does not exist!</p>
<?php 
            } else {
                $res->fetchInto($row);
                $res->free();
                if ($row['question'][strlen($row['question']) - 1] != '?') {
                    $row['question'] .= '?';
                }
                $form2 = new HTML_QuickForm('forgotForm2', 'post', 'index.php?view=login&task=forgot2&handle=' . $_GET['handle']);
                $form2->addElement('header', null, 'Password Recovery: Step 2');
                $form2->addElement('static', null, 'Secret Question:', $row['question']);
                $form2->addElement('text', 'secret', 'Secret Answer:');
                $form2->addElement('submit', null, 'Next');
                $form2->applyFilter('secret', 'trim');
                $form2->addRule('secret', 'Answer is required for verification.', 'required', null, 'client');
                if ($form2->validate()) {
                    if ($form2->getSubmitValue('secret') == $row['secret']) {
                        $res =& db_query('clean_forgot', $row['user_id']);
                        $new_pass = Text_Password::create(10);
                        $res =& $db->autoExecute('users', array('password' => crypt($new_pass)), DB_AUTOQUERY_UPDATE, 'user_id=' . $row['user_id']);
                        if (PEAR::isError($res)) {
                            error($res->toString());
                        }
                        $res =& $db->autoExecute('forgot', array('user_id' => $row['user_id'], 'password' => $new_pass), DB_AUTOQUERY_INSERT);
                        if (PEAR::isError($res)) {
                            error($res->toString());
                        }
                        ?>
<p>Due to lack of emailing support on our server (Yes! We require better servers!), your password will
have to be emailed to you manually. You should receive your newly generated password within 12 hours.</p>
<?php 
                    } else {
                        ?>
<p><strong>Incorrect answer!</strong><br /> We need to verify your identity before we can proceed. Please try again.</p> 
<?php 
                        $form2->display();
                    }
                } else {
                    $form2->display();
                }
            }
            break;
        case 'profile':
            ?>
<p>You can view or edit your personal information here. 
Any fields that you leave blank will <i>remain unchanged</i>.</p>
<?php 
            $form = new HTML_QuickForm('profileForm', 'post', 'index.php?view=login&task=profile');
            $res =& db_query('user_by_id', $_SESSION['user_id']);
            $res->fetchInto($row);
            $res->free();
            $form->addElement('header', null, 'Edit Your Profile');
            $form->addElement('static', 'handle', 'Handle:');
            $form->addElement('password', 'password', 'Change Password:'******'password', 'password2', 'Retype Password:'******'text', 'email', 'Email:');
            $form->addElement('header', null, 'Personal Information');
            $form->addElement('text', 'first_name', 'First Name:');
            $form->addElement('text', 'last_name', 'Last Name:');
            $date = getdate();
            $form->addElement('date', 'birth_date', 'Date of Birth:', array('minYear' => $date['year'] - 100, 'maxYear' => $date['year']));
            $form->addElement('text', 'address', 'Street Address:');
            $form->addElement('text', 'city', 'City:');
            $form->addElement('text', 'state', 'State:');
            $form->addElement('text', 'zip', 'Zip:');
            $form->addElement('static', null, 'Division:', $cfg['tcl']['divisions'][$row['division']]);
            $form->addElement('text', 'phone', 'Phone:');
            $form->addElement('textarea', 'quote', 'Quote:');
            $form->addElement('submit', null, 'Save Changes');
            unset($row['password']);
            // Format the birth date
            $row['birth_date'] = sql2form_date($row['birth_date']);
            $form->setDefaults($row);
            $form->applyFilter('email', 'trim');
            $form->applyFilter('first_name', 'trim');
            $form->applyFilter('last_name', 'trim');
            $form->applyFilter('address', 'trim');
            $form->applyFilter('state', 'trim');
            $form->applyFilter('city', 'trim');
            $form->applyFilter('zip', 'trim');
            $form->applyFilter('phone', 'trim');
            $form->addRule('password', 'Password must be between 6 and 15 characters.', 'rangelength', array(4, 15), 'client');
            $form->addRule('email', 'Email is invalid.', 'email', null, 'client');
            $form->addRule(array('password', 'password2'), 'Passwords much match.', 'compare', null, 'client');
            if ($form->validate()) {
                $data = $form->getSubmitValues();
                unset($data['password2']);
                // Format the birth date correctly
                $data['birth_date'] = form2sql_date($data['birth_date']);
                foreach ($data as $key => $value) {
                    if ($value == $row['value'] || strlen($value) == 0) {
                        unset($data[$key]);
                    }
                }
                //print_r($data);
                auth_update($data);
                redirect('index.php?view=login&task=profile&updated=1');
            } else {
                $form->display();
            }
            if ($_GET['updated'] == '1') {
                ?>
                <p><b>Note:</b> Your profile has been updated.</p>
            <?php 
            }
            break;
    }
}
コード例 #9
0
function bulletin_display($task)
{
    global $db;
    switch ($task) {
        case 'announce':
            bulletin_tabulate(0);
            break;
        case 'show':
            $res =& db_query('bulletin_by_id', array($_GET['id']));
            $res->fetchInto($row);
            $res =& db_query('user_by_id', array($row['poster_id']));
            $res->fetchInto($user);
            echo "<h1>{$row['subject']}</h1>";
            //        $table->addRow(array('Subject: <b>'.$row['subject'].'</b>', 'Posted by: <b>'.user_handle($row['handle']).'</b>'.$action));
            if ($row['addbreaks'] == 1) {
                echo '<div class="message">' . preg_replace('/\\n/', '<br />', $row['message']) . '</div>' . '<i>The above message was posted by <b>' . user_handle($user['handle']) . '</b> on ' . $row['posted'] . '.</i>';
            } else {
                echo '<div class="message">' . $row['message'] . '</div>' . '<i>The above message was posted by <b>' . user_handle($user['handle']) . '</b> on ' . $row['posted'] . '.</i>';
            }
            break;
        case 'analysis':
            bulletin_tabulate(1);
            break;
        case 'admin':
            bulletin_tabulate(2);
            break;
        case 'public':
            bulletin_tabulate(3);
            break;
        case 'edit':
            $form = new HTML_QuickForm('shoutForm', 'post', selflink());
            $form->addElement('header', null, 'Post your message here:');
            $form->addElement('text', 'subject', 'Subject: ');
            $elem =& $form->addElement('checkbox', 'addbreaks', null);
            $elem->setChecked(false);
            $elem->setText('Allow HTML formatting tags. Makes line-break tags necessary.');
            $elem =& $form->addElement('textarea', 'message', 'Shout Message: ');
            $elem->setRows(20);
            $elem->setCols(60);
            $form->addElement('submit', null, 'Post');
            $form->addRule('subject', 'Subject must be maximum 100 characters.', 'maxlength', 100, 'client');
            $res =& db_query('bulletin_by_id', array($_GET['id']));
            $res->fetchInto($row);
            if ($row['addbreaks'] == 1) {
                unset($row['addbreaks']);
            } else {
                $row['addbreaks'] = 1;
            }
            $form->setDefaults($row);
            $res->free();
            if ($form->validate()) {
                $data = $form->getSubmitValues();
                if (!isset($data['addbreaks'])) {
                    $data['addbreaks'] = 1;
                    $data['message'] = htmlentities($data['message']);
                } else {
                    $data['addbreaks'] = 0;
                }
                $res =& $db->autoExecute('bulletin', $data, DB_AUTOQUERY_UPDATE, 'post_id=' . $_GET['id']);
                if (PEAR::isError($res)) {
                    error($res->toString());
                }
                redirect('index.php?view=bulletin&task=' . $_GET['prev']);
            } else {
                $form->display();
            }
            break;
        case 'delete':
            db_query('delete_bulletin_by_id', array($_GET['id']));
            redirect('index.php?view=bulletin&task=' . $_GET['prev']);
            break;
    }
}
コード例 #10
0
ファイル: Form.php プロジェクト: rk4an/centreon
 /**
  * 
  * @param type $field Specific rules
  * @return type
  */
 private function removeSpaces($field)
 {
     $ret = $this->formProcessor->getSubmitValues();
     return str_replace(" ", "_", $ret[$field]);
 }
コード例 #11
0
function submit_field($contest_id, $team_id, &$problem, $practiceMode = false)
{
    global $cfg;
    if ($practiceMode == true) {
        // Check for running contests in practice mode
        $res =& db_query('count_running_contests');
        $res->fetchInto($count);
        if ($count['count'] > 0) {
            ?>
            <p class="system_info"><b>Sorry, solution form is disabled in practice mode.</b><br />
            This is to preserve server resources for the running contest. Practice submissions will be re-enabled when that contest is over.</p>
            <?php 
            return;
        }
    }
    html_include_js($cfg['dir']['scripts'] . '/editor.js');
    $langs = language_list();
    $languages = array();
    foreach ($langs as $lang) {
        require_once $cfg['dir']['languages'] . '/' . $lang . '.php';
        $func = 'lang_' . $lang . '_description';
        $languages[$lang] = $func();
    }
    $lang = $langs[0];
    $source = '';
    $res =& db_query('draft_by_user', array($_SESSION['user_id']));
    if ($res->fetchInto($draft)) {
        if ($draft['contest_id'] == $contest_id && $draft['prob_id'] == $problem['prob_id']) {
            $lang = $draft['language'];
            $source = $draft['source'];
        }
    }
    // Code editing form
    $form = new HTML_QuickForm('submitForm', 'post', selflink() . '#results');
    $e =& $form->addElement('select', 'language', 'Language: ', $languages);
    if (!isset($_POST['language'])) {
        $e->setValue($lang);
    }
    $e =& $form->addElement('textarea', 'source', 'Code: ', array('rows' => 12, 'class' => 'editor'));
    if (!isset($_POST['source'])) {
        $e->setValue($source);
    }
    $form->addElement('html', "\n" . '<tr><td align="right" valign="top"><div id="custom_input1" style="display:none"><b>Custom<br/>Input: </b></div></td>
    		<td><div id="custom_input2" style="display:none"><textarea rows="4" class="editor" name="custom">' . $_POST['custom'] . '</textarea></div></td></tr>' . "\n");
    $form->addElement('html', "\n" . '<tr><td align="right" valign="top"></td><td valign="top" align="left"><input name="test" value="Compile and Test" type="submit"/>
    		<input onclick="handleTestButton()" id="custom_button" name="customb" value="Test with custom input" type="button" />' . "\n");
    if ($practiceMode == false) {
        $form->addElement('html', ' <input name="submitit" value="Submit" type="submit" /></td></tr>');
    } else {
        $form->addElement('html', '</td></tr>');
    }
    $form->applyFilter('source', 'trim');
    //$form->addRule('source', 'Source code area is blank! Refusing to accept.', 'required', null, 'client');
    // Display some text & the form
    ?>
<div class="mimic_para">
<a id="shortcuts_link" onclick="toggleShowShortcuts()" href="#solution">[+] Useful Editor Shortcuts:</a>
<div id="shortcuts"></div>
</div>
<?php 
    html_javascript_check();
    html_rounded_box_open();
    $form->display();
    echo '<div id="edit_status"></div>';
    html_rounded_box_close();
    if ($form->validate()) {
        echo "<a name=\"results\"></a>";
        ?>
<p class="lower"><b>Tester:</b><br /> Please be patient while your code is being compiled and tested.
Results will be displayed in the frame below.</p>
<?php 
        $solution =& $form->getSubmitValues();
        $mode = "";
        if ($practiceMode) {
            $mode = "practice";
        } else {
            if (isset($solution['submitit'])) {
                $mode = "submit";
            }
        }
        if ($id = submit_record($contest_id, $problem['prob_id'], $solution, $mode)) {
            html_rounded_box_open();
            ?>
<iframe width="90%" height="300" scrolling="yes" src="<?php 
            echo "progress.php?id={$id}";
            ?>
">
<!-- Following gets displayed if IFRAME is not supported -->
<b>Your browser is not supported!</b><br />
Please upgrade your browser, as it lacks basic support for inline-frames,
which is necessary for this feature. Recommended browsers are 
<a href="http://www.getfirefox.com">Mozilla/Firefox</a>,
Internet Explorer 5.0+ and Opera 7.0+.
</iframe>
            <?php 
            html_rounded_box_close();
        }
    }
}