/** * View list * * @author John.meng * @since version1.0 - Dec 12, 2005 */ function viewList() { global $__Lang__, $FlushPHPObj, $smarty; include_once PEAR_DIR . "HTML/Table.php"; include_once PEAR_DIR . "HTML/QuickForm.php"; include_once APP_DIR . "UI.class.php"; $form =& new HTML_QuickForm(); $FilesDirsObj = $FlushPHPObj->loadUtility("FilesDirs"); $FilesDirsObj->FilesDirs(MODULE_DIR, 1, "CVS,General"); $Module_arr = $FilesDirsObj->listDirs(); asort($Module_arr); reset($Module_arr); $data = array(); $installImageObj = new UIImage(THEMES_DIR . "images/install.gif"); $unInstallImageObj = new UIImage(THEMES_DIR . "images/uninstall.gif"); if (sizeof($Module_arr)) { foreach ($Module_arr as $key => $value) { $temp_Module_arr = $FlushPHPObj->getModuleInfo($value); if (file_exists(MODULE_DIR . "/" . $temp_Module_arr['name'] . "/" . $temp_Module_arr['logo']) && $temp_Module_arr['logo']) { $ModuleImageLogo = new UIImage(MODULE_DIR . "/" . $temp_Module_arr['name'] . "/" . $temp_Module_arr['logo']); $Module_logo = $ModuleImageLogo->toHTML() . "<br/>"; } $data[$key] = array($Module_logo . $temp_Module_arr['name'] . " <b> " . $temp_Module_arr['version'] . " <b/> ", $temp_Module_arr['description'], $temp_Module_arr['author'], $unInstallImageObj->toHTML() . "<br/>" . $__Lang__['langGeneralUnInstall'], $installImageObj->toHTML() . "<br/>" . $__Lang__['langGeneralInstall']); } } $tableAttrs = array("class" => "grid_table"); $table = new HTML_Table($tableAttrs); $table->setAutoGrow(true); $table->setAutoFill("n/a"); for ($nr = 0; $nr < count($data); $nr++) { $table->setHeaderContents($nr + 1, 0, (string) $nr); for ($i = 0; $i < 5; $i++) { if ("" != $data[$nr][$i]) { $table->setCellContents($nr + 1, $i + 1, $data[$nr][$i]); } } } $table->setColAttributes(3, array(" align" => "center")); $table->setColAttributes(4, array(" align" => "center")); $table->setColAttributes(5, array(" align" => "center")); $altRow = array("class" => "grid_table_tr_alternate"); $table->altRowAttributes(1, null, $altRow); $table->setHeaderContents(0, 0, ""); $table->setHeaderContents(0, 1, $__Lang__['langMenuModule']); $table->setHeaderContents(0, 2, $__Lang__['langGeneralSummary']); $table->setHeaderContents(0, 3, $__Lang__['langGeneralAuthor']); $table->setHeaderContents(0, 4, $__Lang__['langGeneralStatus']); $table->setHeaderContents(0, 5, $__Lang__['langGeneralOperation']); $hrAttrs = array("class" => "grid_table_head"); $table->setRowAttributes(0, $hrAttrs, true); $table->setColAttributes(0, $hrAttrs); $smarty->assign("Main", $table->toHtml()); }
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&task=show_problem&id={$_GET['id']}&prob_id={$row['prob_id']}\">show</a>"; $row['actions'] = "<a href=\"index.php?view=manage&task=edit_problem&id={$_GET['id']}&prob_id={$row['prob_id']}\">edit</a>, " . "<a href=\"index.php?view=manage&task=del_problem&id={$_GET['id']}&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&&task=test&updateratings=false&id=<?php echo $_GET['id']; ?> ">Test and grade all submissions.</a> <a class="button" href="index.php?view=manage&task=test&updateratings=true&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&task=test&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&task=contest&id=' . $_GET['id'] . '">See the results.</a>'; html_footer(); exit; } }
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&task=edit_user&id={$row['user_id']}\">edit</a>" . ", <a href=\"index.php?view=admin&task=del_user&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&task=edit_group&id={$row['group_id']}\">edit</a>" . ", <a href=\"index.php?view=admin&task=del_group&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&task=edit_contest&id={$row['contest_id']}\">edit</a>, " . "<a href=\"index.php?view=admin&task=del_contest&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; } }
function statistics_display($task) { global $db, $cfg; switch ($task) { case 'overall': ?> <p><b>Overall member ratings.</b><br />Below are the present standings of all registered members, based on ratings calculated over their performance in various contests.</p> <?php //for($i = 0; $i < 3; $i++) //{ if(!isset($_GET['div'])) { $_GET['div'] = '0'; } echo '<p><b>'; $i = 0; for($i = '0'; $i < $cfg["tcl"]["divcount"]; $i++) { if($i == $_GET['div']) echo $cfg["tcl"]["divisions"][$_GET['div']]; else echo '<a href="index.php?view=statistics&task=overall&div='.$i.'">'.$cfg["tcl"]["divisions"][$i].'</a>'; if($i <> $cfg["tcl"]["divcount"] - '1') echo ' | '; } /* while(true) { echo 'here'; if($i != $_GET['div']) echo $cfg["tcl"]["divisions"][$_GET['div']]; else echo '<a href="index.php?view=statistics&task=overall&div='.$i; if($i != 2) { echo ' | '; break; } $i++; };*/ echo '</b></p>'; $table = new HTML_Table; $table->addRow(array('<a href="index.php?view=statistics&task=overall">Rank</a>', '<a href="index.php?view=statistics&task=overall&sort=handle">User Handle</a>', 'Name', '<a href="index.php?view=statistics&task=overall">Rating</a>', '<a href="index.php?view=statistics&task=overall&sort=volatility">Volatility</a>', 'Participated contests'), null, 'TH'); if (!isset($_GET['sort'])) { $_GET['sort'] = 'rating DESC'; } $res =& $db->query('SELECT user_id, first_name, last_name, handle, rating, volatility FROM users WHERE division = '.$_GET['div'].' ORDER BY '.$_GET['sort']); if (PEAR::isError($res)) error($res->toString()); $prev_rat = -1; $rank = 0; $carried = 0; while ($res->fetchInto($user)) { if ($user['handle'] == 'tester') continue; if (abs($prev_rat-$user['rating']) < 1e-4) { ++$carried; } else { $rank = $rank + $carried + 1; $prev_rat = $user['rating']; $carried = 0; } $res2 =& $db->query('SELECT COUNT(*) AS count FROM members WHERE user_id = '.$user['user_id']); if (PEAR::isError($res)) error($res->toString()); $res2->fetchInto($count); $res2->free(); $table->addRow(array($rank, user_handle($user['handle']), ucwords(strtolower($user['first_name'].' '.$user['last_name'])), $user['rating'], $user['volatility'], $count['count'])); } $res->free(); $table->altRowAttributes(1, null, array ("class" => "altrow")); echo '<div class="overflow">'.$table->toHtml().'</div>'; //} break; case 'contest': $res =& db_query('contest_by_id', $_GET['id']); $res->fetchInto($contest); $res->free(); /* if ($contest['tested'] != 1 && $contest['end_future'] != 1 && !auth_user_in_group('Administrators')) { ?> <p><b>System tests for this contest have not finished yet.</b><br /> Contest statistics containing the scores and standings of each team will be put up here, once the testing phase is over. Please check back in a few minutes.</p> <?php return; } */ $table = new HTML_Table; if ($contest['show_future'] == 1) { $status = 'Hidden (not activated yet)'; } else if ($contest['begin_future'] == 1) { $status = 'Not started'; } else if ($contest['end_future'] == 1) { $status = 'Running'; } else { $status = 'Ended'; } $table->addRow(array('Contest status: ', $status), null, 'TH'); $table->addRow(array('Name: ', $contest['name'])); $table->addRow(array('Description: ', $contest['description'])); $table->addRow(array('Begin time: ', $contest['begin_time'])); $table->addRow(array('End time: ', $contest['end_time'])); if ($contest['team_size'] != 1) { $table->addRow(array('Max size of team: ', $contest['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($count); $res->free(); $table->addRow(array($prefix.' registered: ', $count['count'])); $table->altRowAttributes(1, null, array ("class" => "altrow")); echo '<div class="overflow">'.$table->toHtml().'</div>'; echo "<hr />\n"; if ($contest['end_future'] == 1) { ?> <p><b>Contest Standings.</b><br/></p> <?php } else { ?> <p><b>System testing results.</b><br /> For details about particular solutions, please click on the underlined scores.</p> <?php } $header = array('Rank'); array_push($header, 'Coder'); array_push($header, 'College'); $probs = array(); $res =& db_query('problems_by_contest_id', $_GET['id']); while ($res->fetchInto($problem)) { array_push($header, '<i>'.$problem['prob_id'].'</i>'); array_push($probs, $problem['prob_id']); } $res->free(); array_push($header, 'Score'); $table = new HTML_Table; $table->addRow($header, null, 'TH'); if ($contest['end_future'] != 1) $res =& db_query('teams_by_contest_id', $_GET['id']); else $res =& db_query('standings_by_contest_id', $_GET['id']); if ($res->numRows() == 0) { ?> <p><b>No Rankings!</b><br />No teams participated in this contest.</p> <?php return; } $prev_score = -1; $rank = 0; $carried = 0; while ($res->fetchInto($team)) { // calculate rank if (abs($prev_score-$team['score']) < 1e-4) { ++$carried; } else { $rank = $rank + $carried + 1; $prev_score = $team['score']; $carried = 0; } $row = array($rank, $team['name'], $team['college']); // add users if ($contest['team_size'] > 1) { $res2 =& db_query('users_by_team_id', array($_GET['id'], $team['team_id'])); if ($res2->fetchInto($user)) { $users = user_handle($user['handle']); while ($res2->fetchInto($user)) { $users .= ', '.user_handle($user['handle']); } } $res2->free(); array_push($row, $users); } // add prob scores foreach ($probs as $prob_id) { $res2 =& db_query('score_by_id', array($_GET['id'], $team['team_id'], $prob_id)); if ($res2->fetchInto($solution) && isset($solution['language'])) { if ($contest['end_future'] == 1) array_push($row, sprintf("%.3f", $solution['score'])); else array_push($row, '<a target="_blank" href="solution.php?id='.$_GET['id'].'&prob_id='.$prob_id.'&team_id='.$team['team_id'].'">'.sprintf("%.3f", $solution['score']).'</a>'); } else { array_push($row, '-'); } $res2->free(); } // add total score array_push($row, sprintf("%.3f", $team['score'])); $table->addRow($row); } $table->altRowAttributes(1, null, array ("class" => "altrow")); echo '<div class="overflow">'.$table->toHtml().'</div>'; break; case 'profile': $table = new HTML_Table; $res =& db_query('user_by_handle', $_GET['handle']); if (!$res->fetchInto($user)) { ?> <p><b>No such handle!</b><br/>Maybe you mistyped the user handle.</p> <?php; return; } $table->addRow(array('User handle: ', $_GET['handle']), null, 'TH'); $table->addRow(array('Division: ', $cfg["tcl"]["divisions"][$user['division']])); $table->addRow(array('Rating: ', $user['rating'])); $table->addRow(array('Volatility: ', $user['volatility'])); $table->addRow(array('Name: ', $user['first_name'].' '.$user['last_name'])); $table->addRow(array('Date of Birth: ', $user['birth_date'])); $table->addRow(array('City: ', $user['city'])); $table->addRow(array('Country: ', $user['country'])); $table->addRow(array('Quote: ', $user['quote'])); $table->altRowAttributes(1, null, array ("class" => "altrow")); echo '<div class="overflow">'.$table->toHtml().'</div>'; break; } }
echo '<b>Language:</b> ' . $func(); echo '<pre class="solution_code">'; echo html_escape($soln['source']); echo '</pre>'; ob_end_flush(); if ($contest['end_future'] != '1' && ($contest['tested'] == 1 || auth_user_in_group('Administrators'))) { // Show test-case passing summary require_once 'problem.php'; require_once 'HTML/Table.php'; $table = new HTML_Table(); $table->addRow(array('Test Case', 'Passed', 'Input'), null, 'TH'); $res =& db_query('problem_by_id', array($_GET['prob_id'], $_GET['id'])); $res->fetchInto($problem); $prob = problem_load($problem); $show_eg = strlen($soln['passed']) == count($prob->tests); $i = '0'; foreach ($prob->tests as $id => $case) { if (!$show_eg && array_key_exists($id, $prob->examples)) { continue; } $passed = "no"; if ($soln['passed'][$i] == '1') { $passed = "yes"; } $table->addRow(array($i, $passed, '<pre>' . $case->getInput() . '</pre>')); ++$i; } $table->altRowAttributes(1, null, array("class" => "altrow")); echo '<div class="overflow">' . $table->toHtml() . '</div>'; } html_footer();
function getDetails($id, $tplname = 'details.tpl.html') { $this->tpl = new HTML_Template_IT($basedir); $this->tpl->loadTemplateFile($this->basedir . $tplname); $query = "select * from " . $this->cfg['table']['compound'] . " where id = {$id}"; $row = $this->db_con->getRow($query); $this->tpl->setVariable("HEADING", $row->{"name_" . LC_LANG}); $this->tpl->setVariable('LC_SPECIFICATIONS', $this->lang->translate('specifications')); $query = "select *,comp.id as mixid, comp.name_de as mischname_de,comp.name_en as mischname_en,cat_comp.name_de as mischkatname_de,cat_comp.name_en as mischkatname_en\n from " . $this->cfg['table']['cat_compound'] . ' as cat_comp, ' . $this->cfg['table']['compound'] . " as comp\n where comp.id_mischungkat=cat_comp.id AND comp.id={$id}"; $row = $this->db_con->getRow($query); include_once 'HTML/Table.php'; $tbl = new HTML_Table('class="overview"'); $tbl->addRow(array($this->lang->translate('name'), $row->{"mischname_" . LC_LANG})); $tbl->addRow(array($this->lang->translate('category'), $row->{"mischkatname_" . LC_LANG})); $tbl->addRow(array('M100', $row->m100)); $tbl->addRow(array('M300', $row->m300)); $tbl->addRow(array('TS', $row->ts)); $tbl->addRow(array('EAB', $row->eab)); $tbl->addRow(array('Rebound', $row->rebound)); $tbl->addRow(array('Shore A', $row->shore_a)); $tbl->addRow(array('SG', $row->sg)); $tbl->setColAttributes(0, 'width="100"'); $tbl->setColAttributes(1, 'width="300"'); $row1Style = array('class' => 'overview'); $row2Style = array('class' => 'overviewalternate'); $tbl->altRowAttributes(0, $row1Style, $row2Style); $this->tpl->setVariable("COMPOUND_DATA", $tbl->toHTML()); $tbl = new HTML_Table('class="overview"'); $tbl->addRow(array('Name', 'phr'), 'class="overview"', 'TH'); $query = "select * from " . $this->cfg['table']['details_compound'] . " where id_mischung={$id}"; $this->db_res = $this->db_con->Query($query); while ($row = $this->db_res->fetchrow(DB_FETCHMODE_OBJECT)) { if ($row->id_produkt) { $_url = '<a class="maroon" href="' . url(array('module' => 'product', 'action' => 'details', 'id' => $row->id_produkt)) . '">' . $row->name . '</a>'; } else { $_url = $row->name; } $tbl->addRow(array($_url, $row->phr)); } $query = "select sum(phr) as phrsum from " . $this->cfg['table']['details_compound'] . " where id_mischung={$id}"; $row = $this->db_con->getRow($query); $tbl->addRow(array('', $row->phrsum)); $tbl->updateColAttributes(1, 'align="right" "bgcolor=#eeeeee"'); $tbl->updateRowAttributes($tbl->getrowCount() - 1, "bgcolor=#CCCCCC"); $this->tpl->setVariable('TBL_DETAILS', $tbl->toHTML()); $this->tpl->setVariable("CATEGORY_COLOR", $this->color); return $this->tpl->get(); }
/** * Get HTML table (as string that can be echoed) * * @param array $row_data (to appear in rows of table) * @param array $column_headers (to appear in head of table * @return string * * @access public */ public function get_table($row_data, $column_headers) { // see http://pear.php.net/manual/en/package.html.html-table.intro.php $table = new HTML_Table(); $table->setAutoGrow(true); $table->setAutoFill('n/a'); for ($nr = 0, $maxr = count($row_data); $nr < $maxr; $nr++) { for ($i = 0, $ii = count($column_headers); $i < $ii; $i++) { if ('' != $row_data[$nr][$i]) { $table->setCellContents($nr + 1, $i, $row_data[$nr][$i]); } } } for ($i = 0, $ii = count($column_headers); $i < $ii; $i++) { $table->setHeaderContents(0, $i, $column_headers[$i]); } $header_attribute = array('class' => 'header'); $table->setRowAttributes(0, $header_attribute, true); $table->setColAttributes(0, $header_attribute); $altRow = array('class' => 'alt_row'); $table->altRowAttributes(1, null, $altRow); return $table->toHtml(); }
/** * Get HTML table (as string that can be echoed) * * @param array $row_data (to appear in rows of table) * @param array $column_headers (to appear in head of table * @return string * * @access private */ private function get_table($row_data, $column_headers, $delete = false, $deleteColumn = -999, $deleteField = 'dummy-field-name') { // see http://pear.php.net/manual/en/package.html.html-table.intro.php $table = new HTML_Table(); $table->setAutoGrow(true); $table->setAutoFill('n/a'); for ($nr = 0, $maxr = count($row_data); $nr < $maxr; $nr++) { for ($i = 0, $ii = count($column_headers); $i < $ii; $i++) { if (isset($row_data[$nr][$i])) { if ('' != $row_data[$nr][$i]) { if ($deleteColumn == $i) { if ($delete) { $table->setCellContents($nr + 1, $i, $this->getDeleteButton($row_data[$nr][$i], $deleteField)); } } else { $table->setCellContents($nr + 1, $i, $row_data[$nr][$i]); } } } else { $table->setCellContents($nr + 1, $i, $this->fillerForEmptyCell); } } } for ($i = 0, $ii = count($column_headers); $i < $ii; $i++) { $table->setHeaderContents(0, $i, $column_headers[$i]); } $header_attribute = array('class' => 'header'); $table->setRowAttributes(0, $header_attribute, true); $table->setColAttributes(0, $header_attribute); $altRow = array('class' => 'alt_row'); $table->altRowAttributes(1, null, $altRow); return $table->toHtml(); }
$link_back .= url(array('module' => 'product', 'action' => 'overview', 'id' => $category)); $link_back .= '">'; $link_back .= $lang->translate("back"); $link_back .= '</a>'; include_once 'HTML/Table.php'; $tbl = new HTML_Table('class="overview"'); $tbl->addRow(array($lang->translate('name'), $row->{product_name})); $tbl->addRow(array($lang->translate('chemical nomenclature'), $row->{info . '_' . LC_LANG})); $tbl->addRow(array($lang->translate('further information'), $row->{bem_ . LC_LANG})); $tbl->addRow(array($lang->translate('manufacturer'), '<a href="' . url(array('module' => 'company', 'action' => 'details', 'id' => $row->id)) . '"><img src="' . $cfg['path']['logo'] . $row->url_logo . '"><br>' . $row->{company_name} . '</a>')); $tbl->addRow(array($lang->translate('website'), $row->product_url)); $tbl->setColAttributes(0, 'width="100"'); $tbl->setColAttributes(1, 'width="300"'); $row1Style = array('class' => 'overview'); $row2Style = array('class' => 'overviewalternate'); $tbl->altRowAttributes(0, $row1Style, $row2Style); $tpl->setVariable("UEBERSCHRIFT", $row->product_name); $tpl->SetVariable("TABELLE_UEBERSCHRIFT", $row->product_name . " (" . $link_back . ")"); /** BEGIN Vertrieb **/ $query = "select *,t_reseller.name as reseller\n from {$table['product']},{$table['company']} as t_reseller, {$table['reseller']}\n where {$table['product']}.id={$id}\n AND {$table['product']}.id={$table['reseller']}.id_produkt\n AND {$table['reseller']}.id_firma=t_reseller.id"; require_once 'mms_tablepager.php'; $tabpage = new PageTable($cfg['database']['dsn'], "overview"); $tabpage->fields = array('name', 'land'); $tabpage->make_url = false; $tabpage->add_extra = false; $tabpage->col_view = 'name'; $tabpage->url_view = url(array('module' => 'company', 'action' => 'details')); $res_vertrieb = '<h2>' . $lang->translate('reseller') . '</h2>' . $tabpage->get($query, $from, 'overview') . '<br>'; /** END Vertrieb **/ /** BEGIN Beispielmischungen **/ $query = "select *,{$table['compound']}.id as mixid, {$table['compound']}.name_" . LC_LANG . " as mischname from {$table['product']},{$table['compound_details']},{$table['compound']} where {$table['compound_details']}.id_produkt={$table['product']}.id AND {$table['compound']}.id = {$table['compound_details']}.id_mischung AND {$table['product']}.id={$id}";
<?php $data = array('0' => array('Bakken', 'Stig', '', '*****@*****.**'), '1' => array('Merz', 'Alexander', 'alex.example.com', '*****@*****.**'), '2' => array('Daniel', 'Adam', '', '')); require_once 'HTML/Table.php'; $attrs = array('width' => '600'); $table = new HTML_Table($attrs); $table->setAutoGrow(true); $table->setAutoFill('n/a'); for ($nr = 0; $nr < count($data); $nr++) { // La primer columna es cabecera de tabla tambien $table->setHeaderContents($nr + 1, 0, (string) $nr); for ($i = 0; $i <= 3; $i++) { if ('' != $data[$nr][$i]) { $table->setCellContents($nr + 1, $i + 1, $data[$nr][$i]); } } } $altRow = array('bgcolor' => 'red'); $table->altRowAttributes(1, null, $altRow); $table->setHeaderContents(0, 0, ''); $table->setHeaderContents(0, 1, 'Surname'); $table->setHeaderContents(0, 2, 'Name'); $table->setHeaderContents(0, 3, 'Website'); $table->setHeaderContents(0, 4, 'EMail'); $hrAttrs = array('bgcolor' => 'silver'); $table->setRowAttributes(0, $hrAttrs, true); $table->setColAttributes(0, $hrAttrs); echo $table->toHtml();
/** fiches_a_valider () - Renvoie les annonces restant a valider par un administrateur * * @return string HTML */ function fiches_a_valider() { // Pour les administrateurs d'une rubrique, on affiche les fiches a valider de cette rubrique // On effectue une requete sur le bazar pour voir les fiches a administrer $GLOBALS['_BAZAR_']['url']->addQueryString(BAZ_VARIABLE_VOIR, BAZ_VOIR_ADMIN); $res = '<h2>' . BAZ_ANNONCES_A_ADMINISTRER . '</h2><br />' . "\n"; $requete = 'SELECT * FROM ' . BAZ_PREFIXE . 'fiche, ' . BAZ_PREFIXE . 'nature WHERE bf_statut_fiche=0 AND ' . 'bn_id_nature=bf_ce_nature AND bn_ce_id_menu IN (' . $GLOBALS['_BAZAR_']['categorie_nature'] . ') '; if (isset($GLOBALS['_BAZAR_']['langue'])) { $requete .= ' and bn_ce_i18n like "' . $GLOBALS['_BAZAR_']['langue'] . '%" '; } $requete .= 'ORDER BY bf_date_maj_fiche DESC'; $resultat = $GLOBALS['_BAZAR_']['db']->query($requete); if (DB::isError($resultat)) { echo 'Echec de la requete<br />' . $resultat->getMessage() . '<br />' . $resultat->getDebugInfo(); } if ($resultat->numRows() != 0) { $tableAttr = array('id' => 'table_bazar'); $table = new HTML_Table($tableAttr); $entete = array(BAZ_TITREANNONCE, BAZ_ANNONCEUR, BAZ_TYPE_FICHE, BAZ_PUBLIER, BAZ_SUPPRIMER); $table->addRow($entete); $table->setRowType(0, 'th'); // On affiche une ligne par proposition while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) { //Requete pour trouver le nom et prenom de l'annonceur $requetenomprenom = 'SELECT ' . BAZ_CHAMPS_PRENOM . ', ' . BAZ_CHAMPS_NOM . ' FROM ' . BAZ_ANNUAIRE . ' WHERE ' . BAZ_CHAMPS_ID . '=' . $ligne['bf_ce_utilisateur']; $resultatnomprenom = $GLOBALS['_BAZAR_']['db']->query($requetenomprenom); if (DB::isError($resultatnomprenom)) { echo "Echec de la requete<br />" . $resultatnomprenom->getMessage() . "<br />" . $resultatnomprenom->getDebugInfo(); } while ($lignenomprenom = $resultatnomprenom->fetchRow(DB_FETCHMODE_ASSOC)) { $annonceur = $lignenomprenom[BAZ_CHAMPS_PRENOM] . " " . $lignenomprenom[BAZ_CHAMPS_NOM]; } $lien_voir = $GLOBALS['_BAZAR_']['url']; $lien_voir->addQueryString(BAZ_VARIABLE_ACTION, BAZ_VOIR_FICHE); $lien_voir->addQueryString('id_fiche', $ligne['bf_id_fiche']); //$lien_voir->addQueryString('typeannonce', $ligne['bn_id_nature']); // Nettoyage de l'url // NOTE (jpm - 23 mai 2007): pour �tre compatible avec PHP5 il faut utiliser tjrs $GLOBALS['_BAZAR_']['url'] car en php4 on // copie bien une variable mais pas en php5, cela reste une r�f�rence... $GLOBALS['_BAZAR_']['url']->removeQueryString(BAZ_VARIABLE_ACTION); $GLOBALS['_BAZAR_']['url']->removeQueryString('id_fiche'); //$GLOBALS['_BAZAR_']['url']->removeQueryString('typeannonce'); $GLOBALS['_BAZAR_']['url']->addQueryString('id_fiche', $ligne['bf_id_fiche']); $GLOBALS['_BAZAR_']['url']->addQueryString('typeannonce', $ligne['bn_id_nature']); $GLOBALS['_BAZAR_']['url']->addQueryString(BAZ_VARIABLE_ACTION, BAZ_VOIR_FICHE); $lien_voir = $GLOBALS['_BAZAR_']['url']->getURL(); $GLOBALS['_BAZAR_']['url']->removeQueryString(BAZ_VARIABLE_ACTION); $GLOBALS['_BAZAR_']['url']->addQueryString(BAZ_VARIABLE_ACTION, BAZ_ACTION_PUBLIER); $lien_publie_oui = $GLOBALS['_BAZAR_']['url']->getURL(); $GLOBALS['_BAZAR_']['url']->removeQueryString(BAZ_VARIABLE_ACTION); $GLOBALS['_BAZAR_']['url']->addQueryString(BAZ_VARIABLE_ACTION, BAZ_ACTION_PAS_PUBLIER); $lien_publie_non = $GLOBALS['_BAZAR_']['url']->getURL(); $GLOBALS['_BAZAR_']['url']->removeQueryString(BAZ_VARIABLE_ACTION); $GLOBALS['_BAZAR_']['url']->addQueryString(BAZ_VARIABLE_ACTION, BAZ_ACTION_SUPPRESSION); $lien_supprimer = $GLOBALS['_BAZAR_']['url']->getURL(); $GLOBALS['_BAZAR_']['url']->removeQueryString(BAZ_VARIABLE_ACTION); $GLOBALS['_BAZAR_']['url']->removeQueryString('id_fiche'); $GLOBALS['_BAZAR_']['url']->removeQueryString('typeannonce'); $table->addRow(array('<a href="' . $lien_voir . '">' . $ligne['bf_titre'] . '</a>' . "\n", $annonceur . "\n", $ligne['bn_label_nature'] . "\n", "<a href=\"" . $lien_publie_oui . "\">" . BAZ_OUI . "</a> / \n" . "<a href=\"" . $lien_publie_non . "\">" . BAZ_NON . "</a>", "<a href=\"" . $lien_supprimer . "\"" . " onclick=\"javascript:return confirm('" . BAZ_CONFIRMATION_SUPPRESSION . "');\">" . BAZ_SUPPRIMER . "</a>\n")); // col 5 : supprimer } $table->altRowAttributes(1, array("class" => "ligne_impaire"), array("class" => "ligne_paire")); $table->updateColAttributes(1, array("align" => "center")); $table->updateColAttributes(2, array("align" => "center")); $table->updateColAttributes(3, array("align" => "center")); $table->updateColAttributes(4, array("align" => "center")); $res .= $table->toHTML(); } else { $res .= '<p class="zone_info">' . BAZ_PAS_DE_FICHE_A_VALIDER . '</p>' . "\n"; } $GLOBALS['_BAZAR_']['url']->addQueryString(BAZ_VARIABLE_ACTION, BAZ_VOIR_TOUTES_ANNONCES); // Nettoyage de l'url $GLOBALS['_BAZAR_']['url']->removeQueryString(BAZ_VARIABLE_ACTION); $GLOBALS['_BAZAR_']['url']->removeQueryString('id_fiche'); $GLOBALS['_BAZAR_']['url']->removeQueryString('typeannonce'); // Les autres fiches, deja validees $res .= '<h2>' . BAZ_TOUTES_LES_FICHES . '</h2>' . "\n"; $requete = 'SELECT * FROM ' . BAZ_PREFIXE . 'fiche, ' . BAZ_PREFIXE . 'nature WHERE bf_statut_fiche=1 AND ' . 'bn_id_nature=bf_ce_nature AND bn_ce_id_menu IN (' . $GLOBALS['_BAZAR_']['categorie_nature'] . ') '; if (isset($GLOBALS['_BAZAR_']['langue'])) { $requete .= ' and bn_ce_i18n like "' . $GLOBALS['_BAZAR_']['langue'] . '%" '; } $requete .= 'ORDER BY bf_date_maj_fiche DESC'; $resultat = $GLOBALS['_BAZAR_']['db']->query($requete); if (DB::isError($resultat)) { echo 'Echec de la requete<br />' . $resultat->getMessage() . '<br />' . $resultat->getDebugInfo(); } if ($resultat->numRows() != 0) { $tableAttr = array('class' => 'table_bazar'); $table = new HTML_Table($tableAttr); $entete = array(BAZ_TITREANNONCE, BAZ_ANNONCEUR, BAZ_TYPE_FICHE, BAZ_PUBLIER, BAZ_SUPPRIMER); $table->addRow($entete); $table->setRowType(0, 'th'); // On affiche une ligne par proposition while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) { //Requete pour trouver le nom et prenom de l'annonceur $requetenomprenom = 'SELECT ' . BAZ_CHAMPS_PRENOM . ', ' . BAZ_CHAMPS_NOM . ' FROM ' . BAZ_ANNUAIRE . ' WHERE ' . BAZ_CHAMPS_ID . '=' . $ligne['bf_ce_utilisateur']; $resultatnomprenom = $GLOBALS['_BAZAR_']['db']->query($requetenomprenom); if (DB::isError($resultatnomprenom)) { echo "Echec de la requete<br />" . $resultatnomprenom->getMessage() . "<br />" . $resultatnomprenom->getDebugInfo(); } while ($lignenomprenom = $resultatnomprenom->fetchRow(DB_FETCHMODE_ASSOC)) { $annonceur = $lignenomprenom[BAZ_CHAMPS_PRENOM] . " " . $lignenomprenom[BAZ_CHAMPS_NOM]; } $lien_voir = $GLOBALS['_BAZAR_']['url']; $lien_voir->addQueryString(BAZ_VARIABLE_ACTION, BAZ_VOIR_FICHE); $lien_voir->addQueryString('id_fiche', $ligne['bf_id_fiche']); $lien_voir->addQueryString('typeannonce', $ligne['bn_id_nature']); // Nettoyage de l'url // NOTE (jpm - 23 mai 2007): pour être compatible avec PHP5 il faut utiliser tjrs $GLOBALS['_BAZAR_']['url'] car en php4 on // copie bien une variable mais pas en php5, cela reste une référence... $GLOBALS['_BAZAR_']['url']->removeQueryString(BAZ_VARIABLE_ACTION); $GLOBALS['_BAZAR_']['url']->removeQueryString('id_fiche'); $GLOBALS['_BAZAR_']['url']->removeQueryString('typeannonce'); $GLOBALS['_BAZAR_']['url']->addQueryString('id_fiche', $ligne['bf_id_fiche']); $GLOBALS['_BAZAR_']['url']->addQueryString('typeannonce', $ligne['bn_id_nature']); $GLOBALS['_BAZAR_']['url']->addQueryString(BAZ_VARIABLE_ACTION, BAZ_VOIR_FICHE); $lien_voir = $GLOBALS['_BAZAR_']['url']->getURL(); $GLOBALS['_BAZAR_']['url']->removeQueryString(BAZ_VARIABLE_ACTION); $GLOBALS['_BAZAR_']['url']->addQueryString(BAZ_VARIABLE_ACTION, BAZ_ACTION_PUBLIER); $lien_publie_oui = $GLOBALS['_BAZAR_']['url']->getURL(); $GLOBALS['_BAZAR_']['url']->removeQueryString(BAZ_VARIABLE_ACTION); $GLOBALS['_BAZAR_']['url']->addQueryString(BAZ_VARIABLE_ACTION, BAZ_ACTION_PAS_PUBLIER); $lien_publie_non = $GLOBALS['_BAZAR_']['url']->getURL(); $GLOBALS['_BAZAR_']['url']->removeQueryString(BAZ_VARIABLE_ACTION); $GLOBALS['_BAZAR_']['url']->addQueryString(BAZ_VARIABLE_ACTION, BAZ_ACTION_SUPPRESSION); $lien_supprimer = $GLOBALS['_BAZAR_']['url']->getURL(); $GLOBALS['_BAZAR_']['url']->removeQueryString(BAZ_VARIABLE_ACTION); $GLOBALS['_BAZAR_']['url']->removeQueryString('id_fiche'); $GLOBALS['_BAZAR_']['url']->removeQueryString('typeannonce'); $table->addRow(array('<a href="' . $lien_voir . '">' . $ligne['bf_titre'] . '</a>' . "\n", $annonceur . "\n", $ligne['bn_label_nature'] . "\n", "<a href=\"" . $lien_publie_oui . "\">" . BAZ_OUI . "</a> / \n" . "<a href=\"" . $lien_publie_non . "\">" . BAZ_NON . "</a>", "<a href=\"" . $lien_supprimer . "\"" . " onclick=\"javascript:return confirm('" . BAZ_CONFIRMATION_SUPPRESSION . "');\">" . BAZ_SUPPRIMER . "</a>\n")); // col 5 : supprimer } $table->altRowAttributes(1, array("class" => "ligne_impaire"), array("class" => "ligne_paire")); $table->updateColAttributes(1, array("align" => "center")); $table->updateColAttributes(2, array("align" => "center")); $table->updateColAttributes(3, array("align" => "center")); $table->updateColAttributes(4, array("align" => "center")); $res .= $table->toHTML(); } $GLOBALS['_BAZAR_']['url']->removeQueryString(BAZ_VARIABLE_VOIR); return $res; }
/** * function_description * * @author John.meng * @since version - Jan 6, 2006 * @param datatype paramname description * @return datatype description */ function opStep3() { global $__Lang__, $UrlParameter, $SiteDB, $AddIPObj, $FlushPHPObj, $form, $smarty, $__MODULE__, $__TEMPLATES__; include_once PEAR_DIR . "HTML/Table.php"; include_once MODULE_DIR . "Site/DAO/SiteMenuDAO.class.php"; parent::opAdd(); $form->addElement('header', null, $__Lang__['langSite'] . $__Lang__['langWizard'] . $__Lang__['langStep'] . " 3 "); $sysMenuDao = new SiteMenuDAO(); $data_menu = $sysMenuDao->getMenuAllArr(); $tableAttrs = array("class" => "grid_sub_table", 'cellspacing' => "0"); $table = new HTML_Table($tableAttrs); $table->setAutoGrow(true); // $table->setAutoFill("n/a"); $cell_x = 0; $data_menu = array(NULL => NULL) + $data_menu; foreach ($data_menu as $key => $value) { $table->addRow(array($value['Title'], $__MODULE__[$value['Module']], $__TEMPLATES__[$value['Template']], $value['URL'], " <table><tr><td><a href='####' onclick=\"popOpenWindow('PopupWindow.php', '', 'Module=" . $_REQUEST['Module'] . "&Page=SiteMenu&Action=Update&ID=" . $key . "' , 450, 450)\" ><img src='" . THEMES_DIR . "images/edit.gif' border='0'><br />" . $__Lang__['langGeneralUpdate'] . "</a></td><td><a href='####' onclick=\"confirm ( '" . $__Lang__['langGeneralCancelConfirm'] . "')?popOpenWindow('PopupWindow.php', '', 'Module=" . $_REQUEST['Module'] . "&Page=SiteMenu&Action=Cancel&ID=" . $key . "' , 20, 20):'';\"><img src='" . THEMES_DIR . "images/delete.gif' border='0'><br />" . $__Lang__['langGeneralCancel'] . "</a></td></tr></table>")); $cell_x++; } $altRow = array("class" => "grid_table_tr_alternate"); $table->altRowAttributes(1, null, $altRow); $hrAttrs = array("class" => "grid_sub_table_head"); $table->setRowAttributes(0, $hrAttrs, true); $table->setHeaderContents(0, 0, $__Lang__['langMenu']); $table->setHeaderContents(0, 1, $__Lang__['langSiteModule']); $table->setHeaderContents(0, 2, $__Lang__['langSiteTemplate']); $table->setHeaderContents(0, 3, $__Lang__['langGeneralURL']); $table->setHeaderContents(0, 4, $__Lang__['langGeneralOperation']); $form->addElement('static', NULL, NULL, $table->toHtml()); $step_nav[] =& HTML_QuickForm::createElement('submit', 'btnPre', $__Lang__['langPreStep'], "onclick=document.forms[0].Step.value='Step2' "); $step_nav[] =& HTML_QuickForm::createElement('button', 'btnNew', $__Lang__['langGeneralAdd'] . $__Lang__['langMenu'], "onclick=\"popOpenWindow('PopupWindow.php', '', 'Module=" . $_REQUEST['Module'] . "&Page=SiteMenu&Action=Add', 450, 450)\" "); $step_nav[] =& HTML_QuickForm::createElement('button', 'btnNext', $__Lang__['langFinish'], "onclick=\"window.location='?Module=Site&Page=Preview'\" "); $form->addGroup($step_nav, 'step_navigation', " "); $form->addElement('hidden', 'Module', $_REQUEST['Module']); $form->addElement('hidden', 'Page', $_REQUEST['Page']); $form->addElement('hidden', 'Action', $_REQUEST['Action']); $form->addElement('hidden', 'Step'); if ($form->validate()) { if ($_POST['Step'] == 'Step2') { $this->_redirectURL("?Module=" . $_REQUEST['Module'] . "&Page=" . $_REQUEST['Page'] . "&Action=Step2"); } else { $this->_redirectURL("?Module=" . $_REQUEST['Module'] . "&Page=" . $_REQUEST['Page'] . "&Action=Step4"); } } $smarty->assign("Main", $form->toHTML()); }
th, td { padding: 0.4em; } tr.alt td { background: #ddd; } </style> </head> <body> <h2>Fibonacci sequence using HTML_Table</h2> <?php require_once "HTML/Table.php"; $attrs = array("cellspacing" => 0, "border" => 0, "style" => "width: 20em; border: 1px solid #666;"); $table = new HTML_Table($attrs); $table->addRow(array("Sequence #", "Value"), null, "th"); $iterations = 10; $num1 = 0; $num2 = 1; $table->addRow(array("F<sub>0</sub>", "0")); $table->addRow(array("F<sub>1</sub>", "1")); for ($i = 2; $i <= $iterations; $i++) { $sum = $num1 + $num2; $num1 = $num2; $num2 = $sum; $table->addRow(array("F<sub>{$i}</sub>", $num2)); } $attrs = array("class" => "alt"); $table->altRowAttributes(1, null, $attrs, true); echo $table->toHtml(); ?> </body> </html>
function bulletin_tabulate($level) { global $db, $cfg; $start_limit = 0; if (array_key_exists('start', $_GET)) { $start_limit = $_GET['start']; } $count_limit = 15; if (array_key_exists('count', $_GET)) { $start_limit = $_GET['count']; } $is_admin = auth_user_in_group('Administrators'); if (!$is_admin && $level == 2) { error("Admin Chat not authorised for non-admins."); } if ($level > 2 || $is_admin) { $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(6); $elem->setCols(60); $form->addElement('submit', 'submit', 'Post'); $form->addRule('subject', 'Subject must be maximum 100 characters.', 'maxlength', 100, 'client'); if ($form->validate()) { $data = $form->getSubmitValues(); if (!isset($data['addbreaks'])) { $data['addbreaks'] = 1; $data['message'] = htmlentities($data['message']); } else { $data['addbreaks'] = 0; } db_query('bulletin_post', array($_SESSION['user_id'], $data['subject'], $data['message'], $level, $data['addbreaks'])); redirect('index.php?view=bulletin&task=' . $_GET['task']); } } if ($level > 2 || $is_admin) { $form->display(); echo '<hr />'; } bulletin_navbar($start_limit, $count_limit); $res =& $db->query($cfg['sql']['bulletin_by_level'] . " LIMIT {$start_limit}, {$count_limit}", array($level)); if (PEAR::isError($res)) { error($res->toString()); } $table = new HTML_Table(); if ($res->numRows() == 0) { $table->addRow(array('Sorry, no more messages on this bulletin page.')); } while ($res->fetchInto($row)) { $action = ""; if ($row['poster_id'] == $_SESSION['user_id']) { $action = ' [<a href="index.php?view=bulletin&task=edit&prev=' . $_GET['task'] . '&id=' . $row['post_id'] . '">edit</a>, <a href="index.php?view=bulletin&task=delete&prev=' . $_GET['task'] . '&id=' . $row['post_id'] . '">delete</a>]'; } else { if ($is_admin) { $action = ' [<a href="index.php?view=bulletin&task=delete&prev=' . $_GET['task'] . '&id=' . $row['post_id'] . '">delete</a>]'; } } $table->addRow(array('Subject: <b>' . $row['subject'] . '</b>', 'Posted by: <b>' . user_handle($row['handle']) . '</b>' . $action . ' on <i>' . $row['posted'] . '</i>')); if ($row['addbreaks'] == 1) { $table->addRow(array('<div class="message">' . preg_replace('/\\n/', '<br />', $row['message']) . '</div>'), array(colspan => "2")); } else { $table->addRow(array('<div class="message">' . $row['message'] . '</div>'), array(colspan => "2")); } } $table->altRowAttributes(0, array("class" => "altrow"), null); echo $table->toHtml(); bulletin_navbar($start_limit, $count_limit); }