Commit fd9d0e7f authored by pkdille's avatar pkdille

Some code cleanup (seen on quality.tiki.org)

parent 624c4cbb
This diff is collapsed.
......@@ -160,16 +160,23 @@ class TikiSheet
var $rangeBeginCol = -1;
var $rangeEndCol = -1;
function getRangeBeginRow() {
function getRangeBeginRow()
{
return $this->rangeBeginRow > -1 ? $this->rangeBeginRow : 0;
}
function getRangeEndRow() {
function getRangeEndRow()
{
return $this->rangeEndRow > -1 ? $this->rangeEndRow : $this->getRowCount();
}
function getRangeBeginCol() {
function getRangeBeginCol()
{
return $this->rangeBeginCol > -1 ? $this->rangeBeginCol : 0;
}
function getRangeEndCol() {
function getRangeEndCol()
{
return $this->rangeEndCol > -1 ? $this->rangeEndCol : $this->getColumnCount();
}
......@@ -332,7 +339,8 @@ class TikiSheet
* @param bool $incsubs Include sub-sheets
* @param timestamp $date Date (revision) to read sub-sheets from
*/
function getTableHtml( $incsubs = true, $date = null, $fromDb = true ) {
function getTableHtml( $incsubs = true, $date = null, $fromDb = true )
{
global $prefs, $sheetlib;
$handler = new TikiSheetOutputHandler(null, ($this->parseValues == 'y' && $_REQUEST['parse'] != 'n'));
......@@ -502,7 +510,8 @@ class TikiSheet
* Limits display (so far)
* a given range (ex: A1:B9)
*/
function setRange( $range ) {
function setRange( $range )
{
if( preg_match( '/^([A-Z]+)([0-9]+):([A-Z]+)([0-9]+)$/', strtoupper($range), $parts ) ) {
$this->rangeBeginRow = $parts[2] - 1;
$this->rangeEndRow = $parts[4] - 1;
......@@ -519,13 +528,15 @@ class TikiSheet
return $this->rowCount;
}
function getTitle() {
function getTitle()
{
global $sheetlib;
$info = $sheetlib->get_sheet_info($this->sheetId);
return $info['title'];
}
function getInstance() {
function getInstance()
{
return $this->instance;
}
......@@ -784,7 +795,8 @@ class TikiSheetDataHandler
trigger_error( "Abstract method call. version() not defined in " . get_class( $this ), E_USER_ERROR );
}
function parseCsv( &$sheet ) {
function parseCsv( &$sheet )
{
$rows = explode("\n", $this->data);
for($i = 0; $i < count($rows) && $i < $this->maxrows; $i++) {
$cols = preg_split("/[,;](?!(?:[^\\\",;]|[^\\\"],[^\\\"])+\\\")/", $rows[$i]);
......@@ -2168,7 +2180,8 @@ class TikiSheetHTMLTableHandler extends TikiSheetDataHandler
}
// _load {{{2
function _load( TikiSheet &$sheet ) {
function _load( TikiSheet &$sheet )
{
$d = $this->data;
......@@ -2359,13 +2372,15 @@ class SheetLib extends TikiLib
return $sheetId;
}
function set_sheet_title( $sheetId, $title ) {
function set_sheet_title( $sheetId, $title )
{
if ( $sheetId ) {
$this->query( "UPDATE `tiki_sheets` SET `title` = ? WHERE `sheetId` = ?", array( $title, $sheetId ) );
}
}
function setup_jquery_sheet() {
function setup_jquery_sheet()
{
global $headerlib;
if (!$this->setup_jQuery_sheet_files) {
$headerlib->add_cssfile( 'lib/jquery/jquery.sheet/jquery.sheet.css' );
......@@ -2386,7 +2401,8 @@ class SheetLib extends TikiLib
}
}
function sheet_history( $sheetId ) {
function sheet_history( $sheetId )
{
return $this->fetchAll( "
SELECT DISTINCT
`tiki_sheet_values`.`begin` as stamp,
......@@ -2398,7 +2414,8 @@ class SheetLib extends TikiLib
ORDER BY begin DESC", array( $sheetId, $sheetId ) );
}
function rollback_sheet($id, $readdate=null) {
function rollback_sheet($id, $readdate=null)
{
global $user, $sheetlib;
if ($readdate) {
......@@ -2437,7 +2454,8 @@ class SheetLib extends TikiLib
return $id;
}
function clone_sheet( $sheetId, $readdate = null, $parentSheetId = 0) {
function clone_sheet( $sheetId, $readdate = null, $parentSheetId = 0)
{
global $user, $prefs;
if (!isset($readdate)) {
......@@ -2520,7 +2538,8 @@ class SheetLib extends TikiLib
return true;
}
function save_sheet($data, $id, $file, $type = 'db') {
function save_sheet($data, $id, $file, $type = 'db')
{
global $user, $sheetlib;
$sheets = json_decode($data);
......@@ -2558,8 +2577,8 @@ class SheetLib extends TikiLib
}
}
}
} else {
/*
} /*else {
$grid = new TikiSheet();
if ($type == 'csv') {
foreach ($sheets as $sheet) {
......@@ -2577,8 +2596,8 @@ class SheetLib extends TikiLib
$rc .= tra("file - ").$file;
}
}
}*/
}
}
}*/
return ($res ? tra('Saved'). ': ' . $rc : tra('Save failed'));
}
......@@ -2587,7 +2606,8 @@ class SheetLib extends TikiLib
* @param $style A simple css style string used with an html dom object
* @param $attr The name of the css attribute you'd like to extract from $style
*/
function get_attr_from_css_string($style, $attr, $default) {
function get_attr_from_css_string($style, $attr, $default)
{
global $sheetlib;
$style = strtolower($style);
$style = str_replace(' ', '', $style);
......@@ -2759,13 +2779,15 @@ class SheetLib extends TikiLib
return array($result1, $result2);
}
function user_can_view($sheetId) {
function user_can_view($sheetId)
{
global $user;
$objectperms = Perms::get( 'sheet', $sheetId );
return ( $objectperms->view_sheet || $objectperms->admin );
}
function user_can_edit($sheetId) {
function user_can_edit($sheetId)
{
global $user;
$objectperms = Perms::get( 'sheet', $sheetId );
return ( $objectperms->edit_sheet || $objectperms->admin );
......
......@@ -23,5 +23,3 @@ function smarty_modifier_currency($string, $dec_point=',', $thousands='.')
{
return number_format($string, 2, $dec_point, $thousands);
}
?>
......@@ -6262,10 +6262,10 @@ if( \$('#$id') ) {
$in_empty_paragraph = 0;
}
$line = "<br />" . $line;
} else {
// A normal in-paragraph line or a consecutive blank line.
// Leave it as is.
}
} // else {
// A normal in-paragraph line or a consecutive blank line.
// Leave it as is.
// }
}
} elseif (($prefs['wysiwyg_htmltowiki'] === 'y' && !empty($tline) && strpos($tline, '<br />') === false) || !$options['is_html']) {
$line .= "<br />";
......
......@@ -1756,10 +1756,6 @@ class TrackerLib extends TikiLib
}
$the_data .= "\n----------\n";
} else if (! in_array($array["type"], array('u', 'g', 'I')) && isset($array['isHidden']) && ($array["isHidden"] == 'p' or $array["isHidden"] == 'y')and $tiki_p_admin_trackers != 'y') {
// hidden field type require tracker amdin perm
} elseif (empty($array["fieldId"])) {
// can have been unset for a user field
} else {
// -----------------------------
// save image on disk
......
......@@ -744,10 +744,6 @@ class Net_POP3
$headers[$name] = $value;
}
}
// Fix up Message-ID header
if (!array_key_exists('Message-ID',$headers)) {
}
return $headers;
}
......
......@@ -128,7 +128,6 @@ if (isset($_REQUEST['send'])) {
}
$smarty->assign('sentresult', true);
} else {
}
$smarty->assign('emails', $emails);
}
......
......@@ -217,7 +217,6 @@ foreach($accs['data'] as $acc) {
}
}
mailin_check_attachments($output, $content, $page, $aux["sender"]["user"]);
} elseif ($acc['type'] == 'wiki-put' || ($acc['type'] == 'wiki' && $method == "PUT")) {
} elseif ($acc['type'] == 'wiki-append' || $acc['type'] == 'wiki-prepend' || ($acc['type'] == 'wiki' && $method == "APPEND") || ($acc['type'] == 'wiki' && $method == "PREPEND")) {
// This is used to UPDATE wiki pages
$body = mailin_get_body($output);
......
......@@ -214,8 +214,6 @@ if (isset($_REQUEST['bothver_idx'])) {
$_REQUEST['newver_idx'] = $_REQUEST['bothver_idx'];
if ($_REQUEST['show_all_versions'] == 'n' && !empty($history_sessions[$_REQUEST['bothver_idx']])) {
$_REQUEST['oldver_idx'] = $_REQUEST['bothver_idx'];
} else {
//$_REQUEST['oldver_idx'] = $_REQUEST['bothver_idx'] - 2;
}
}
if (isset($_REQUEST['newver_idx'])) {
......
......@@ -30,7 +30,7 @@ $access->check_feature('feature_quizzes');
include_once ('lib/userprefs/userprefslib.php');
$smarty->assign('use_24hr_clock', $userprefslib->get_user_clock_pref($user));
// quizId of 0 is used as a place holder; There should NEVER be a row in the
// quizId of 0 is used as a placeholder; There should NEVER be a row in the
// tiki_quizzes table with an id of zero.
if (!isset($_REQUEST["quizId"])) {
$_REQUEST["quizId"] = 0;
......@@ -46,21 +46,22 @@ include_once ("categorize_list.php");
if (isset($_REQUEST["preview"]) || isset($_REQUEST["xmlview"]) || isset($_REQUEST["textview"])) {
echo "line: " . __LINE__ . "<br>";
echo "Sorry, preview, xmlview and textview are not supported in this version.<br>";
// foreach ($_REQUEST as $key => $request){
// echo $key." = ".$request."<br>";
// }
die;
}
$quiz = $quizlib->quiz_fetch($_REQUEST["quizId"]);
function fetchYNOption(&$quiz, $_REQUEST, $option) {
function fetchYNOption(&$quiz, $_REQUEST, $option)
{
if (isset($_REQUEST[$option]) && $_REQUEST[$option] == 'on') {
$quiz[$option] = 'y';
} else {
$quiz[$option] = 'n';
}
}
// Load the data from the
function quiz_data_load() {
function quiz_data_load()
{
global $_REQUEST;
$quiz_data = array();
foreach($_REQUEST as $key => $val) {
......@@ -82,44 +83,50 @@ function quiz_data_load() {
$_REQUEST['expire_Hour'] = date('H', strtotime($_REQUEST['expire_Hour'] . ':00 ' . $_REQUEST['expire_Meridian']));
}
$quiz_data["datePub"] = TikiLib::make_time($quiz_data["publish_Hour"], $quiz_data["publish_Minute"], 0, $quiz_data["publish_Month"], $quiz_data["publish_Day"], $quiz_data["publish_Year"]);
$quiz_data["dateExp"] = TikiLib::make_time($quiz_data["expire_Hour"], $quiz_data["expire_Minute"], 0, $quiz_data["expire_Month"], $quiz_data["expire_Day"], $quiz_data["expire_Year"]);
$fields = array('nQuestion', 'shuffleAnswers', 'shuffleQuestions', 'multiSession', 'additionalQuestions', 'limitDisplay', 'timeLimited', 'canRepeat', 'additionalQuestions', 'forum');
$quiz_data["datePub"] = TikiLib::make_time($quiz_data["publish_Hour"]
, $quiz_data["publish_Minute"]
, 0
, $quiz_data["publish_Month"]
, $quiz_data["publish_Day"]
, $quiz_data["publish_Year"]
);
$quiz_data["dateExp"] = TikiLib::make_time($quiz_data["expire_Hour"]
, $quiz_data["expire_Minute"]
, 0
, $quiz_data["expire_Month"]
, $quiz_data["expire_Day"]
, $quiz_data["expire_Year"]
);
$fields = array('nQuestion'
, 'shuffleAnswers'
, 'shuffleQuestions'
, 'multiSession'
, 'additionalQuestions'
, 'limitDisplay'
, 'timeLimited'
, 'canRepeat'
, 'additionalQuestions'
, 'forum'
);
foreach($fields as $field) {
fetchYNOption($quiz_data, $quiz_data, $field);
// echo '$quiz_data["'.$field.'"] = '.$quiz_data[$field]."<br>";
}
return $quiz_data;
}
if (isset($_REQUEST["save"])) {
check_ticket('edit-quiz-question');
// echo __FILE__." line ".__LINE__."<br />";
// foreach($_REQUEST as $key => $val){
// if (preg_match("/^quiz_/",$key)){
// echo $key." = ".$val."<br />";
// }
// }
// die;
$quiz_data = quiz_data_load();
// foreach($quiz_data as $key => $val){
// echo $key." = ".$val."<br />";
// }
// die;
$quizNew = new Quiz;
$quizNew->data_load($quiz_data);
// echo __FILE__." line: ".__LINE__."<br />";
// if the id is 0, use just save the new data
// otherwise we compare the data to what was there before.
if ($quiz->id == 0 || ($quizNew != $quiz)) {
$quizlib->quiz_store($quizNew);
// tell user changes were stored (new quiz stored with id of x or quiz x modified), return to list of admin quizzes
} else {
// tell user no changes were stored, return to list of admin quizzes
}
// This way for including questions is was too complicated. Need to think of a simpler way.
}
die;
echo "line: " . __LINE__ . "<br>";
echo "Sorry, this is only a prototype at present.<br>";
......@@ -132,21 +139,11 @@ if (isset($_REQUEST["save"])) {
}
die;
}
// Scaffolding
// The taken and history stuff has to come from version and studentAttempts fields in
// the tiki_quiz table in the database.
// $quiz->taken = 'y';
// $quiz->history = array();
// $quiz->history[] = "and so on...";
// $quiz->history[] = "Version 3 (date stamp) was attempted by students 3 time(s).";
// $quiz->history[] = "Version 2 (date stamp) was attempted by students 2 time(s).";
// $quiz->history[] = "Version 1 (date stamp) was attempted by students 1 time(s).";
$smarty->assign('quiz', $quiz);
// echo __LINE__."<br>";
// echo '$quiz->id = '.$quiz->id."<br>";
// die;
function setup_options(&$tpl) {
// global $smarty;
function setup_options(&$tpl)
{
global $tikilib;
global $user;
$tpl['online_choices'] = array('online' => 'Online', 'offline' => 'Offline');
......@@ -178,6 +175,7 @@ function setup_options(&$tpl) {
$tpl['qpp'] = $qpp;
$tpl['siteTimeZone'] = $prefs['display_timezone'];
}
$tpl = array();
setup_options($tpl);
$smarty->assign('tpl', $tpl);
......
......@@ -329,9 +329,8 @@ if ( isset($_REQUEST["send"]) && ! empty($_REQUEST["sendingUniqId"]) || $resend
} else {
$_SESSION["sendingUniqIds"][ $_REQUEST["sendingUniqId"] ] = 1;
}
} else {
}
$nllib->send($nl_info, $_REQUEST, true, $sent, $errors, $logFileName);
$nb_sent = count($sent);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment