Exemple #1
0
 /**
  * 
  * @param type $elem
  * @return string
  */
 public function getSubmitValue($elem = null)
 {
     if (!isset($elem)) {
         return $this->formProcessor->getSubmitValue();
     } else {
         return $this->formProcessor->getSubmitValue($elem);
     }
 }
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;
    }
}
$redirect =& $form->addElement('hidden', 'o');
$redirect->setValue($o);
/*
 * Form Rules
 */
$form->applyFilter('_ALL_', 'trim');
$form->addRule('refresh_monitoring', _("Required Field"), 'required');
$form->addRule('refresh_filters', _("Required Field"), 'required');
if (isset($cfg_syslog)) {
    $form->setDefaults($cfg_syslog);
} else {
    $form->setDefaults(array("refresh_monitoring " => '10', "refresh_filters" => '240'));
}
#End of form definition
if ($form->validate()) {
    if ($form->getSubmitValue("submitC")) {
        updateRefreshOption();
    }
}
/*
 * Smarty template Init
 */
$tpl = new Smarty();
$tpl = initSmartyTpl($syslog_mod_path . "include/administration", $tpl);
/*
 * Add buttons
 */
if ($o == "m") {
    $subC =& $form->addElement('submit', 'submitC', _("Save"));
    $res =& $form->addElement('reset', 'reset', _("Reset"));
    $redirect->setValue("f");
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;
    }
}
Exemple #5
0
    if ($elem) {
        return rtrim($elem, "/") . "/";
    }
}
$form->addRule('height', _("You need to fix a map height"), 'required', '', 'client');
$form->setJsWarnings(_("Input Error"), "");
$form->applyFilter('_ALL_', 'trim');
$form->setDefaults($sopt);
$form->addElement('submit', 'submitC', _("Save"));
/* 
 * Smarty template Init
 */
$tpl = new Smarty();
$tpl = initSmartyTpl($path, $tpl);
if ($form->validate()) {
    updateGmapCFG($form->getSubmitValue("id"));
    $o = "w";
    $valid = true;
    $sopt = readConfigOptions($pearDB, $oreon);
}
/*
 * Apply a template definition
 */
$renderer =& new HTML_QuickForm_Renderer_ArraySmarty($tpl);
$form->accept($renderer);
$tpl->assign('form', $renderer->toArray());
$tpl->assign('o', $o);
$tpl->assign('valid', $valid);
$tpl->assign("gmap_lat", $sopt['lat']);
$tpl->assign("gmap_lng", $sopt['lng']);
$tpl->assign("gmap_zoom", $sopt['zoomLevel']);
 function getSubmitValue($name)
 {
     return addslashes(parent::getSubmitValue($name));
 }
function spc_like_form()
{
    global $spcIn, $post, $wpdb, $spc, $errors, $recaptcha_opt, $spc_captcha_activated, $spc_mcsp;
    //spc_dg($spcin->get('gil'));
    // Instantiate the HTML_QuickForm object
    $form = new HTML_QuickForm('likeForm', 'POST', $post->guid . "#like");
    $spc_mcsp->GenerateValues();
    $form->setDefaults(array('mcsp_result' => $spc_mcsp->info['result']));
    // Add some elements to the form
    $form->addElement('header', 'notification', '');
    $form->addElement('hidden', 'post_id', $post->ID);
    $form->addElement('hidden', 'comment_id');
    $form->addElement('hidden', 'spcform', 'likeform');
    $form->addElement('text', 'ln', 'Name:', array('size' => 50, 'maxlength' => 255));
    $form->addElement('text', 'le', 'Email:', array('size' => 50, 'maxlength' => 255));
    $form->addElement('header', 'captcha_notification', '');
    $form->addElement('text', 'human_result', $spc_mcsp->info['operand1'] . ' + ' . $spc_mcsp->info['operand2'] . ' = ', array('size' => 2, 'maxlength' => 2));
    $form->addElement('hidden', 'mcsp_result');
    $form->addElement('submit', null, 'VOTE');
    // Define filters and validation rules
    $form->addRule('ln', 'Please enter Your Name', 'required');
    $form->addRule('le', 'Please enter Your Email', 'required');
    $form->addRule('comment_id', 'Sorry Failed, Refresh your browser', 'required');
    $form->registerRule('mcsp_check', 'callback', 'validateMCSP');
    $form->addRule('human_result', 'Wrong Sum', 'mcsp_check', TRUE);
    if ($form->getSubmitValue('spcform') == 'likeform') {
        // Try to validate a form
        if ($form->validate()) {
            $values = $form->exportValues();
            /**/
            $post_id = $values['post_id'];
            $comment_id = $values['comment_id'];
            $participant_vote = $wpdb->get_var("SELECT participant_vote FROM " . $wpdb->spc_participant . " WHERE participant_commentID = " . $comment_id);
            unset($values['post_id'], $values['comment_id'], $values['MAX_FILE_SIZE'], $values['mcsp_result'], $values['human_result']);
            $temp = array();
            $temp = unserialize($participant_vote);
            $temp[] = $values;
            $update_values = array('participant_vote' => serialize($temp));
            if ($wpdb->update($wpdb->spc_participant, $update_values, array('participant_commentID' => $comment_id))) {
                $form->setDefaults(array('notification' => '<div style="width:100%; background-color:white;">Vote Submitted</div>'));
            }
            /**/
        }
        //END form validation
    }
    // Output the form
    $form->display();
}
} else {
    if ($o == "c") {
        $subC =& $form->addElement('submit', 'submitC', _("Save"));
        $res =& $form->addElement('reset', 'reset', _("Reset"));
        $form->setDefaults($report);
    } else {
        if ($o == "a") {
            $subA =& $form->addElement('submit', 'submitA', _("Save"));
            $res =& $form->addElement('reset', 'reset', _("Reset"));
        }
    }
}
$valid = false;
if ($form->validate()) {
    $reportObj =& $form->getElement('report_id');
    if ($form->getSubmitValue("submitA")) {
        $reportObj->setValue(insertReportInDB());
    } else {
        if ($form->getSubmitValue("submitC")) {
            updateReportInDB($reportObj->getValue());
        }
    }
    $o = NULL;
    $form->addElement("button", "change", _("Modify"), array("onClick" => "javascript:window.location.href='?p=" . $p . "&o=c&report_id=" . $reportObj->getValue() . "'"));
    $form->freeze();
    $valid = true;
}
$action =& $form->getSubmitValue("action");
if ($valid && $action["action"]["action"]) {
    require_once $path . "listReport.php";
} else {