本文整理汇总了PHP中F_db_fetch_array函数的典型用法代码示例。如果您正苦于以下问题:PHP F_db_fetch_array函数的具体用法?PHP F_db_fetch_array怎么用?PHP F_db_fetch_array使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了F_db_fetch_array函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: F_importOMRTestData
/**
* Import user's test data from OMR.
* @param $user_id (int) user ID.
* @param $date (string) date-time field.
* @param $omr_testdata (array) Array containing test data.
* @param $omr_answers (array) Array containing test answers (from OMR).
* @return boolean TRUE in case of success, FALSE otherwise.
*/
function F_importOMRTestData($user_id, $date, $omr_testdata, $omr_answers)
{
require_once '../config/tce_config.php';
require_once '../../shared/code/tce_functions_test.php';
global $db, $l;
// check arrays
if (count($omr_testdata) > count($omr_answers) + 1) {
// arrays must contain the same amount of questions
return false;
}
$test_id = intval($omr_testdata[0]);
$user_id = intval($user_id);
$time = strtotime($date);
$date = date(K_TIMESTAMP_FORMAT, $time);
$dateanswers = date(K_TIMESTAMP_FORMAT, $time + 1);
// check user's group
if (F_count_rows(K_TABLE_USERGROUP . ', ' . K_TABLE_TEST_GROUPS . ' WHERE usrgrp_group_id=tstgrp_group_id AND tstgrp_test_id=' . $test_id . ' AND usrgrp_user_id=' . $user_id . ' LIMIT 1') == 0) {
return false;
}
// get test data
$testdata = F_getTestData($test_id);
// 1. delete previous test data
$sqld = 'DELETE FROM ' . K_TABLE_TEST_USER . ' WHERE testuser_test_id=' . $test_id . ' AND testuser_user_id=' . $user_id . '';
if (!($rd = F_db_query($sqld, $db))) {
F_display_db_error();
}
// 2. create new user's test entry
// ------------------------------
$sql = 'INSERT INTO ' . K_TABLE_TEST_USER . ' (
testuser_test_id,
testuser_user_id,
testuser_status,
testuser_creation_time,
testuser_comment
) VALUES (
' . $test_id . ',
' . $user_id . ',
4,
\'' . $date . '\',
\'OMR\'
)';
if (!($r = F_db_query($sql, $db))) {
F_display_db_error(false);
return false;
} else {
// get inserted ID
$testuser_id = F_db_insert_id($db, K_TABLE_TEST_USER, 'testuser_id');
}
// 3. create test log entries
$num_questions = count($omr_testdata) - 1;
// for each question on array
for ($q = 1; $q <= $num_questions; ++$q) {
$question_id = intval($omr_testdata[$q][0]);
$num_answers = count($omr_testdata[$q][1]);
// get question data
$sqlq = 'SELECT question_type, question_difficulty FROM ' . K_TABLE_QUESTIONS . ' WHERE question_id=' . $question_id . ' LIMIT 1';
if ($rq = F_db_query($sqlq, $db)) {
if ($mq = F_db_fetch_array($rq)) {
// question scores
$question_right_score = $testdata['test_score_right'] * $mq['question_difficulty'];
$question_wrong_score = $testdata['test_score_wrong'] * $mq['question_difficulty'];
$question_unanswered_score = $testdata['test_score_unanswered'] * $mq['question_difficulty'];
// add question
$sqll = 'INSERT INTO ' . K_TABLE_TESTS_LOGS . ' (
testlog_testuser_id,
testlog_question_id,
testlog_score,
testlog_creation_time,
testlog_display_time,
testlog_reaction_time,
testlog_order,
testlog_num_answers
) VALUES (
' . $testuser_id . ',
' . $question_id . ',
' . $question_unanswered_score . ',
\'' . $date . '\',
\'' . $date . '\',
1,
' . $q . ',
' . $num_answers . '
)';
if (!($rl = F_db_query($sqll, $db))) {
F_display_db_error(false);
return false;
}
$testlog_id = F_db_insert_id($db, K_TABLE_TESTS_LOGS, 'testlog_id');
// set initial question score
if ($mq['question_type'] == 1) {
// MCSA
$qscore = $question_unanswered_score;
} else {
//.........这里部分代码省略.........
示例2: preg_split
$wherequery = '';
$terms = preg_split("/[\\s]+/i", $searchterms);
// Get all the words into an array
foreach ($terms as $word) {
$word = F_escape_sql($word);
$wherequery .= ' AND (mnf_name LIKE \'%' . $word . '%\')';
}
$wherequery = substr($wherequery, 5);
$sql = 'SELECT * FROM ' . K_TABLE_MANUFACTURES . ' WHERE ' . $wherequery . ' ORDER BY mnf_name ASC';
}
} else {
$sql = 'SELECT mnf_id, mnf_name FROM ' . K_TABLE_MANUFACTURES . ' ORDER BY mnf_name ASC';
}
if ($r = F_db_query($sql, $db)) {
echo '<ul>' . K_NEWLINE;
while ($m = F_db_fetch_array($r)) {
// on click the manufacturer ID will be returned on the calling form field
$jsaction = 'javascript:window.opener.document.getElementById(\'' . $cid . '\').value=' . $m['mnf_id'] . ';';
$jsaction .= 'window.opener.document.getElementById(\'' . $cid . '\').onchange();';
$jsaction .= 'window.close();';
echo '<li><a href="#" onclick="' . $jsaction . '" title="[' . $l['w_select'] . ']">' . htmlspecialchars($m['mnf_name'], ENT_NOQUOTES, $l['a_meta_charset']) . '</a></li>' . K_NEWLINE;
}
echo '</ul>' . K_NEWLINE;
} else {
F_display_db_error();
}
echo '</form>' . K_NEWLINE;
require_once dirname(__FILE__) . '/tce_page_footer_popup.php';
//============================================================+
// END OF FILE
//============================================================+
示例3: F_csv_export_users
/**
* Export all users to CSV grouped by users' groups.
* @author Nicola Asuni
* @since 2006-03-30
* @return CSV data
*/
function F_csv_export_users()
{
global $l, $db;
require_once '../config/tce_config.php';
$csv = '';
// CSV data to be returned
// print column names
$csv .= 'user_id';
$csv .= K_TAB . 'user_name';
$csv .= K_TAB . 'user_password';
$csv .= K_TAB . 'user_email';
$csv .= K_TAB . 'user_regdate';
$csv .= K_TAB . 'user_ip';
$csv .= K_TAB . 'user_firstname';
$csv .= K_TAB . 'user_lastname';
$csv .= K_TAB . 'user_birthdate';
$csv .= K_TAB . 'user_birthplace';
$csv .= K_TAB . 'user_regnumber';
$csv .= K_TAB . 'user_ssn';
$csv .= K_TAB . 'user_level';
$csv .= K_TAB . 'user_verifycode';
$csv .= K_TAB . 'user_groups';
$sql = 'SELECT * FROM ' . K_TABLE_USERS . ' WHERE (user_id>1)';
if ($_SESSION['session_user_level'] < K_AUTH_ADMINISTRATOR) {
// filter for level
$sql .= ' AND ((user_level<' . $_SESSION['session_user_level'] . ') OR (user_id=' . $_SESSION['session_user_id'] . '))';
// filter for groups
$sql .= ' AND user_id IN (SELECT tb.usrgrp_user_id
FROM ' . K_TABLE_USERGROUP . ' AS ta, ' . K_TABLE_USERGROUP . ' AS tb
WHERE ta.usrgrp_group_id=tb.usrgrp_group_id
AND ta.usrgrp_user_id=' . intval($_SESSION['session_user_id']) . '
AND tb.usrgrp_user_id=user_id)';
}
$sql .= ' ORDER BY user_lastname,user_firstname,user_name';
if ($r = F_db_query($sql, $db)) {
while ($m = F_db_fetch_array($r)) {
$csv .= K_NEWLINE . $m['user_id'];
$csv .= K_TAB . $m['user_name'];
$csv .= K_TAB;
// password cannot be exported because is encrypted
$csv .= K_TAB . $m['user_email'];
$csv .= K_TAB . $m['user_regdate'];
$csv .= K_TAB . $m['user_ip'];
$csv .= K_TAB . $m['user_firstname'];
$csv .= K_TAB . $m['user_lastname'];
$csv .= K_TAB . substr($m['user_birthdate'], 0, 10);
$csv .= K_TAB . $m['user_birthplace'];
$csv .= K_TAB . $m['user_regnumber'];
$csv .= K_TAB . $m['user_ssn'];
$csv .= K_TAB . $m['user_level'];
$csv .= K_TAB . $m['user_verifycode'];
$csv .= K_TAB;
$grp = '';
// comma separated list of user's groups
$sqlg = 'SELECT *
FROM ' . K_TABLE_GROUPS . ', ' . K_TABLE_USERGROUP . '
WHERE usrgrp_group_id=group_id
AND usrgrp_user_id=' . $m['user_id'] . '
ORDER BY group_name';
if ($rg = F_db_query($sqlg, $db)) {
while ($mg = F_db_fetch_array($rg)) {
$grp .= $mg['group_name'] . ',';
}
} else {
F_display_db_error();
}
if (!empty($grp)) {
// add user's groups removing last comma
$csv .= substr($grp, 0, -1);
}
}
} else {
F_display_db_error();
}
return $csv;
}
示例4: F_getUserTestStat
/**
* Returns test data structure for selected user:
* <ul>
* <li>$data['all'] = total number of questions</li>
* <li>$data['right'] = number of right answers for multiple-choice questions (score > 50% max points)</li>
* <li>$data['wrong'] = number of wrong answers for multiple-choice questions (score <= 50% max points)</li>
* <li>$data['textright'] = number of right answers for free-text questions (score > 50% max points)</li>
* <li>$data['textwrong'] = number of wrong answers for free-text questions (score <= 50% max points)</li>
* <li>$data['unanswered'] = total number of unanswered questions</li>
* <li>$data['undisplayed'] = total number of undisplayed questions</li>
* <li>$data['basic_score'] = basic points for each difficulty level of questions</li>
* <li>$data['max_score'] = maximum test score</li>
* <li>$data['score'] = user's score</li>
* <li>$data['comment'] = user's test comment</li>
* <li>$data['time'] = user's test start time</li>
* </ul>
* @param $test_id (int) test ID
* @param $user_id (int) user's test ID
* return array $data
*/
function F_getUserTestStat($test_id, $user_id)
{
require_once '../config/tce_config.php';
global $db, $l;
$test_id = intval($test_id);
$user_id = intval($user_id);
$data = array();
// get test default scores
$sql = 'SELECT test_score_right, test_max_score, test_score_threshold
FROM ' . K_TABLE_TESTS . '
WHERE test_id=' . $test_id . '';
if ($r = F_db_query($sql, $db)) {
if ($m = F_db_fetch_array($r)) {
$data['basic_score'] = $m['test_score_right'];
$data['max_score'] = $m['test_max_score'];
$data['score_threshold'] = $m['test_score_threshold'];
}
} else {
F_display_db_error();
}
// total number of questions
$data['all'] = F_count_rows(K_TABLE_TESTS_LOGS . ', ' . K_TABLE_TEST_USER . ', ' . K_TABLE_QUESTIONS, 'WHERE testlog_testuser_id=testuser_id AND testlog_question_id=question_id AND testuser_test_id=' . $test_id . ' AND testuser_user_id=' . $user_id . '');
// number of right answers
$data['right'] = F_count_rows(K_TABLE_TESTS_LOGS . ', ' . K_TABLE_TEST_USER . ', ' . K_TABLE_QUESTIONS, 'WHERE testlog_testuser_id=testuser_id AND testlog_question_id=question_id AND testuser_test_id=' . $test_id . ' AND testuser_user_id=' . $user_id . ' AND testlog_score>((question_difficulty*' . $data['basic_score'] . ')/2)');
// number of wrong answers
$data['wrong'] = F_count_rows(K_TABLE_TESTS_LOGS . ', ' . K_TABLE_TEST_USER . ', ' . K_TABLE_QUESTIONS, 'WHERE testlog_testuser_id=testuser_id AND testlog_question_id=question_id AND testuser_test_id=' . $test_id . ' AND testuser_user_id=' . $user_id . ' AND testlog_score<=((question_difficulty*' . $data['basic_score'] . ')/2)');
// total number of unanswered questions
$data['unanswered'] = F_count_rows(K_TABLE_TESTS_LOGS . ', ' . K_TABLE_TEST_USER, 'WHERE testlog_testuser_id=testuser_id AND testuser_test_id=' . $test_id . ' AND testuser_user_id=' . $user_id . ' AND testlog_change_time IS NULL');
// total number of undisplayed questions
$data['undisplayed'] = F_count_rows(K_TABLE_TESTS_LOGS . ', ' . K_TABLE_TEST_USER, 'WHERE testlog_testuser_id=testuser_id AND testuser_test_id=' . $test_id . ' AND testuser_user_id=' . $user_id . ' AND testlog_display_time IS NULL');
// number of free-text unrated questions
$data['unrated'] = F_count_rows(K_TABLE_TESTS_LOGS . ', ' . K_TABLE_TEST_USER, 'WHERE testlog_testuser_id=testuser_id AND testuser_test_id=' . $test_id . ' AND testuser_user_id=' . $user_id . ' AND testlog_score IS NULL');
// get user's score
$sql = 'SELECT SUM(testlog_score) AS total_score
FROM ' . K_TABLE_TESTS_LOGS . ', ' . K_TABLE_TEST_USER . '
WHERE testlog_testuser_id=testuser_id
AND testuser_user_id=' . $user_id . '
AND testuser_test_id=' . $test_id . '
GROUP BY testuser_id';
if ($r = F_db_query($sql, $db)) {
if ($m = F_db_fetch_array($r)) {
$data['score'] = $m['total_score'];
}
} else {
F_display_db_error();
}
// get user's test comment
$data['comment'] = '';
$sql = 'SELECT testuser_comment, testuser_creation_time
FROM ' . K_TABLE_TEST_USER . '
WHERE testuser_user_id=' . $user_id . '
AND testuser_test_id=' . $test_id . '
LIMIT 1';
if ($r = F_db_query($sql, $db)) {
if ($m = F_db_fetch_array($r)) {
$data['comment'] = $m['testuser_comment'];
$data['time'] = $m['testuser_creation_time'];
}
} else {
F_display_db_error();
}
$sql = 'SELECT testuser_id, testuser_creation_time, testuser_status, MAX(testlog_change_time) AS test_end_time
FROM ' . K_TABLE_TEST_USER . ', ' . K_TABLE_TESTS_LOGS . '
WHERE testlog_testuser_id=testuser_id
AND testuser_test_id=' . $test_id . '
AND testuser_user_id=' . $user_id . '
AND testuser_status>0
GROUP BY testuser_id, testuser_creation_time, testuser_status
LIMIT 1';
if ($r = F_db_query($sql, $db)) {
if ($m = F_db_fetch_array($r)) {
$data['test_start_time'] = $m['testuser_creation_time'];
$data['test_end_time'] = $m['test_end_time'];
$data['testuser_id'] = $m['testuser_id'];
$data['testuser_status'] = $m['testuser_status'];
}
} else {
F_display_db_error();
}
return $data;
//.........这里部分代码省略.........
示例5: F_decode_tcecode
$pdf->Cell($data_cell_width_third, $data_cell_height, '', 0, 0, 'C', 0);
$pdf->SetFont('', 'BIU');
$pdf->Cell(0, $data_cell_height, $l['w_explanation'], 'LTR', 1, '', 0, '', 0);
$pdf->SetFont('', '');
$pdf->writeHTMLCell(0, $data_cell_height, PDF_MARGIN_LEFT + $data_cell_width_third, $pdf->GetY(), F_decode_tcecode($mq['question_explanation']), 'LRB', 1, '', '');
}
if ($show_answers) {
// display alternative answers
$sqla = 'SELECT *
FROM ' . K_TABLE_ANSWERS . '
WHERE answer_question_id=\'' . $mq['question_id'] . '\'
ORDER BY answer_position,answer_isright DESC';
if ($ra = F_db_query($sqla, $db)) {
$idx = 0;
// count items
while ($ma = F_db_fetch_array($ra)) {
$idx++;
$answer_disabled = intval(!F_getBoolean($ma['answer_enabled']));
$answer_isright = intval(F_getBoolean($ma['answer_isright']));
$pdf->Cell($data_cell_width_third, $data_cell_height, '', 0, 0, 'C', 0);
$pdf->Cell($data_cell_width_third, $data_cell_height, $idx, 1, 0, 'C', $answer_disabled);
if ($mq['question_type'] != 4) {
$pdf->Cell($data_cell_width_third / 2, $data_cell_height, $qright[$answer_isright], 1, 0, 'C', $answer_disabled);
} else {
$pdf->Cell($data_cell_width_third / 2, $data_cell_height, '', 1, 0, 'C', $answer_disabled);
}
if ($ma['answer_position'] > 0) {
$pdf->Cell($data_cell_width_third, $data_cell_height, $ma['answer_position'], 1, 0, 'C', $answer_disabled);
} else {
$pdf->Cell($data_cell_width_third, $data_cell_height, '', 1, 0, 'C', $answer_disabled);
}
示例6: while
}
// print answers
// add answers
$answ_id = 0;
// display multiple answers
while (list($key, $answer_id) = each($answers_ids)) {
++$answ_id;
// add answer ID to QR-Code data
$barcode_test_data[$question_order][1][$answ_id] = $answer_id;
// display each answer option
$sqla = 'SELECT *
FROM ' . K_TABLE_ANSWERS . '
WHERE answer_id=' . $answer_id . '
LIMIT 1';
if ($ra = F_db_query($sqla, $db)) {
if ($ma = F_db_fetch_array($ra)) {
$rightanswer = '';
if ($mq['question_type'] == 4) {
$rightanswer = $ma['answer_position'];
} elseif (F_getBoolean($ma['answer_isright'])) {
$rightanswer = 'X';
}
// start transaction
$pdf->startTransaction();
$block_page = $pdf->getPage();
$print_block = 2;
// 2 tries max
while ($print_block > 0) {
// ------------------------------
$pdf->Cell(2 * $data_cell_width_third, $data_cell_height, '', 0, 0, 'C', 0);
// print correct answer in hidden white color
示例7: getPasswordHash
} else {
$xuser_password = getPasswordHash($_POST['xuser_password']);
// one-way password encoding
// check if submitted login information are correct
$sql = 'SELECT * FROM ' . K_TABLE_USERS . ' WHERE user_name=\'' . F_escape_sql($_POST['xuser_name']) . '\' AND user_password=\'' . $xuser_password . '\'';
if ($r = F_db_query($sql, $db)) {
if ($m = F_db_fetch_array($r)) {
// check One Time Password
$otp = false;
if (K_OTP_LOGIN) {
$mtime = microtime(true);
if (isset($_POST['xuser_otpcode']) and !empty($_POST['xuser_otpcode']) and ($_POST['xuser_otpcode'] == F_getOTP($m['user_otpkey'], $mtime) or $_POST['xuser_otpcode'] == F_getOTP($m['user_otpkey'], $mtime - 30) or $_POST['xuser_otpcode'] == F_getOTP($m['user_otpkey'], $mtime + 30))) {
// check if this OTP token has been alredy used
$sqlt = 'SELECT cpsession_id FROM ' . K_TABLE_SESSIONS . ' WHERE cpsession_id=\'' . $_POST['xuser_otpcode'] . '\' LIMIT 1';
if ($rt = F_db_query($sqlt, $db)) {
if (!F_db_fetch_array($rt)) {
// Store this token on the session table to mark it as invalid for 5 minute (300 seconds)
$sqltu = 'INSERT INTO ' . K_TABLE_SESSIONS . ' (
cpsession_id,
cpsession_expiry,
cpsession_data
) VALUES (
\'' . $_POST['xuser_otpcode'] . '\',
\'' . date(K_TIMESTAMP_FORMAT, time() + 300) . '\',
\'300\'
)';
if (!F_db_query($sqltu, $db)) {
F_display_db_error();
}
$otp = true;
}
示例8: endElementHandler
/**
* Sets the end element handler function for the XML parser parser.end_element_handler.
* @param $parser (resource) The first parameter, parser, is a reference to the XML parser calling the handler.
* @param $name (string) The second parameter, name, contains the name of the element for which this handler is called. If case-folding is in effect for this parser, the element name will be in uppercase letters.
* @private
*/
private function endElementHandler($parser, $name)
{
global $l, $db;
require_once '../config/tce_config.php';
require_once 'tce_functions_user_select.php';
switch (strtolower($name)) {
case 'name':
case 'password':
case 'email':
case 'regdate':
case 'ip':
case 'firstname':
case 'lastname':
case 'birthdate':
case 'birthplace':
case 'regnumber':
case 'ssn':
case 'level':
case 'verifycode':
$this->current_data = F_escape_sql(F_xml_to_text($this->current_data));
$this->user_data[$this->current_element] = $this->current_data;
$this->current_element = '';
$this->current_data = '';
break;
case 'group':
$group_name = F_escape_sql(F_xml_to_text($this->current_data));
// check if group already exist
$sql = 'SELECT group_id
FROM ' . K_TABLE_GROUPS . '
WHERE group_name=\'' . $group_name . '\'
LIMIT 1';
if ($r = F_db_query($sql, $db)) {
if ($m = F_db_fetch_array($r)) {
// the group has been already added
$this->group_data[] = $m['group_id'];
} else {
// add new group
$sqli = 'INSERT INTO ' . K_TABLE_GROUPS . ' (
group_name
) VALUES (
\'' . $group_name . '\'
)';
if (!($ri = F_db_query($sqli, $db))) {
F_display_db_error(false);
} else {
$this->group_data[] = F_db_insert_id($db, K_TABLE_GROUPS, 'group_id');
}
}
} else {
F_display_db_error();
}
break;
case 'user':
// insert users
if (!empty($this->user_data['user_name'])) {
if (empty($this->user_data['user_regdate'])) {
$this->user_data['user_regdate'] = date(K_TIMESTAMP_FORMAT);
}
if (empty($this->user_data['user_ip'])) {
$this->user_data['user_ip'] = getNormalizedIP($_SERVER['REMOTE_ADDR']);
}
if (!isset($this->user_data['user_level']) or strlen($this->user_data['user_level']) == 0) {
$this->user_data['user_level'] = 1;
}
if ($_SESSION['session_user_level'] < K_AUTH_ADMINISTRATOR) {
// you cannot edit a user with a level equal or higher than yours
$this->user_data['user_level'] = min(max(0, $_SESSION['session_user_level'] - 1), $this->user_data['user_level']);
// non-administrator can access only to his/her groups
if (empty($this->group_data)) {
break;
}
$common_groups = array_intersect(F_get_user_groups($_SESSION['session_user_id']), $this->group_data);
if (empty($common_groups)) {
break;
}
}
// check if user already exist
$sql = 'SELECT user_id,user_level
FROM ' . K_TABLE_USERS . '
WHERE user_name=\'' . $this->user_data['user_name'] . '\'
OR user_regnumber=\'' . $this->user_data['user_regnumber'] . '\'
OR user_ssn=\'' . $this->user_data['user_ssn'] . '\'
LIMIT 1';
if ($r = F_db_query($sql, $db)) {
if ($m = F_db_fetch_array($r)) {
// the user has been already added
$user_id = $m['user_id'];
if ($_SESSION['session_user_level'] >= K_AUTH_ADMINISTRATOR or $_SESSION['session_user_level'] > $m['user_level']) {
//update user data
$sqlu = 'UPDATE ' . K_TABLE_USERS . ' SET
user_regdate=\'' . $this->user_data['user_regdate'] . '\',
user_ip=\'' . $this->user_data['user_ip'] . '\',
user_name=\'' . $this->user_data['user_name'] . '\',
user_email=' . F_empty_to_null($this->user_data['user_email']) . ',';
//.........这里部分代码省略.........
示例9: F_getUserGroups
/**
* Return the IDs of groups asociated to the selected user.
* @param $user_id (int) User ID.
* @return (array) Array of group IDs.
*/
function F_getUserGroups($user_id)
{
global $l, $db;
require_once '../config/tce_config.php';
$groups = array();
// check if user is an administrator
$sql = 'SELECT usrgrp_group_id FROM ' . K_TABLE_USERGROUP . ' WHERE usrgrp_user_id=' . $user_id . '';
if ($r = F_db_query($sql, $db)) {
while ($m = F_db_fetch_array($r)) {
$groups[] = $m['usrgrp_group_id'];
}
} else {
F_display_db_error();
}
return $groups;
}
示例10: F_clone_child_objects
/**
* Clone the specified object, including child objects
* @param $source_obj_id (int) Source parent object ID.
* @param $target_obj_id (int) Target parent object ID.
*/
function F_clone_child_objects($source_obj_id, $target_obj_id)
{
global $l, $db;
require_once '../config/tce_config.php';
$sql = 'SELECT * FROM ' . K_TABLE_OBJECTS . ', ' . K_TABLE_OBJECTS_MAP . ' WHERE omp_child_obj_id=obj_id AND omp_parent_obj_id=' . $source_obj_id . '';
if ($r = F_db_query($sql, $db)) {
while ($m = F_db_fetch_array($r)) {
// create new object
$sqli = 'INSERT INTO ' . K_TABLE_OBJECTS . ' (
obj_obt_id,
obj_name,
obj_description,
obj_label,
obj_tag,
obj_mnf_id,
obj_owner_id,
obj_tenant_id
) VALUES (
' . $m['obj_obt_id'] . ',
\'' . $m['obj_name'] . '\',
' . F_empty_to_null($m['obj_description']) . ',
' . F_empty_to_null($m['obj_label']) . ',
' . F_empty_to_null($m['obj_tag']) . ',
' . F_empty_to_null($m['obj_mnf_id']) . ',
' . F_empty_to_null($m['obj_owner_id']) . ',
' . F_empty_to_null($m['obj_tenant_id']) . '
)';
if (!($ri = F_db_query($sqli, $db))) {
F_display_db_error(false);
} else {
$child_obj_id = F_db_insert_id($db, K_TABLE_OBJECTS, 'obj_id');
// add new object as child
$sqli = 'INSERT INTO ' . K_TABLE_OBJECTS_MAP . ' (
omp_parent_obj_id,
omp_child_obj_id
) VALUES (
' . $target_obj_id . ',
' . $child_obj_id . '
)';
if (!($ri = F_db_query($sqli, $db))) {
F_display_db_error(false);
}
F_clone_child_objects($m['obj_id'], $child_obj_id);
}
}
} else {
F_display_db_error();
}
}
示例11: while
echo '<div class="preview">' . K_NEWLINE;
$subjlist = '';
$sql = 'SELECT * FROM ' . K_TABLE_TEST_SUBJSET . '
WHERE tsubset_test_id=\'' . $test_id . '\'
ORDER BY tsubset_id';
if ($r = F_db_query($sql, $db)) {
while ($m = F_db_fetch_array($r)) {
$subjlist .= '<li>';
$subjects_list = '';
$sqls = 'SELECT subject_id,subject_name
FROM ' . K_TABLE_SUBJECTS . ', ' . K_TABLE_SUBJECT_SET . '
WHERE subject_id=subjset_subject_id
AND subjset_tsubset_id=\'' . $m['tsubset_id'] . '\'
ORDER BY subject_name';
if ($rs = F_db_query($sqls, $db)) {
while ($ms = F_db_fetch_array($rs)) {
$subjects_list .= '<a href="tce_edit_subject.php?subject_id=' . $ms['subject_id'] . '" title="' . $l['t_subjects_editor'] . '">' . htmlspecialchars($ms['subject_name'], ENT_NOQUOTES, $l['a_meta_charset']) . '</a>, ';
}
} else {
F_display_db_error();
}
// remove last comma + space
$subjlist .= substr($subjects_list, 0, -2);
$subjlist .= '<br />' . K_NEWLINE;
$subjlist .= '<acronym class="offbox" title="' . $l['h_num_questions'] . '">' . $m['tsubset_quantity'] . '</acronym> ';
$subjlist .= '<acronym class="offbox" title="' . $l['h_question_type'] . '">';
if ($m['tsubset_type'] > 0) {
$subjlist .= $qtype[$m['tsubset_type'] - 1];
} else {
// all question types
$subjlist .= '*';
示例12: F_question_copy
/**
* Copy selected question to another topic
* @author Nicola Asuni
* @since 2008-11-26
* @param $question_id (int) question ID
* @param $new_subject_id (int) new subject ID
*/
function F_question_copy($question_id, $new_subject_id)
{
global $l, $db;
require_once '../config/tce_config.php';
$question_id = intval($question_id);
$new_subject_id = intval($new_subject_id);
// check authorization
$sql = 'SELECT subject_module_id FROM ' . K_TABLE_SUBJECTS . ' WHERE subject_id=' . $new_subject_id . ' LIMIT 1';
if ($r = F_db_query($sql, $db)) {
if ($m = F_db_fetch_array($r)) {
$subject_module_id = $m['subject_module_id'];
// check user's authorization for parent module
if (!F_isAuthorizedUser(K_TABLE_MODULES, 'module_id', $subject_module_id, 'module_user_id')) {
return;
}
}
} else {
F_display_db_error();
return;
}
$q = F_question_get_data($question_id);
if ($q !== false) {
if (K_DATABASE_TYPE == 'ORACLE') {
$chksql = 'dbms_lob.instr(question_description,\'' . F_escape_sql($db, $q['question_description']) . '\',1,1)>0';
} elseif (K_DATABASE_TYPE == 'MYSQL' and defined('K_MYSQL_QA_BIN_UNIQUITY') and K_MYSQL_QA_BIN_UNIQUITY) {
$chksql = 'question_description=\'' . F_escape_sql($db, $q['question_description']) . '\' COLLATE utf8_bin';
} else {
$chksql = 'question_description=\'' . F_escape_sql($db, $q['question_description']) . '\'';
}
if (F_check_unique(K_TABLE_QUESTIONS, $chksql . ' AND question_subject_id=' . $new_subject_id . '')) {
$sql = 'START TRANSACTION';
if (!($r = F_db_query($sql, $db))) {
F_display_db_error(false);
break;
}
// adjust questions ordering
if ($q['question_position'] > 0) {
$sql = 'UPDATE ' . K_TABLE_QUESTIONS . ' SET
question_position=question_position+1
WHERE question_subject_id=' . $new_subject_id . '
AND question_position>=' . $q['question_position'] . '';
if (!($r = F_db_query($sql, $db))) {
F_display_db_error(false);
F_db_query('ROLLBACK', $db);
// rollback transaction
}
}
$sql = 'INSERT INTO ' . K_TABLE_QUESTIONS . ' (
question_subject_id,
question_description,
question_explanation,
question_type,
question_difficulty,
question_enabled,
question_position,
question_timer,
question_fullscreen,
question_inline_answers,
question_auto_next
) VALUES (
' . $new_subject_id . ',
\'' . F_escape_sql($db, $q['question_description']) . '\',
\'' . F_escape_sql($db, $q['question_explanation']) . '\',
\'' . $q['question_type'] . '\',
\'' . $q['question_difficulty'] . '\',
\'' . $q['question_enabled'] . '\',
' . F_zero_to_null($q['question_position']) . ',
\'' . $q['question_timer'] . '\',
\'' . $q['question_fullscreen'] . '\',
\'' . $q['question_inline_answers'] . '\',
\'' . $q['question_auto_next'] . '\'
)';
if (!($r = F_db_query($sql, $db))) {
F_display_db_error(false);
} else {
$new_question_id = F_db_insert_id($db, K_TABLE_QUESTIONS, 'question_id');
}
// copy associated answers
$sql = 'SELECT *
FROM ' . K_TABLE_ANSWERS . '
WHERE answer_question_id=' . $question_id . '';
if ($r = F_db_query($sql, $db)) {
while ($m = F_db_fetch_array($r)) {
$sqli = 'INSERT INTO ' . K_TABLE_ANSWERS . ' (
answer_question_id,
answer_description,
answer_explanation,
answer_isright,
answer_enabled,
answer_position,
answer_keyboard_key
) VALUES (
' . $new_question_id . ',
//.........这里部分代码省略.........
示例13: F_syncUserGroups
/**
* Sync user groups with the ones specified on the configuration file for alternate authentication.
* @param $usrid (int) ID of the user to update.
* @param $grpids (mixed) Group ID or comma separated list of group IDs (0=all available groups).
* @author Nicola Asuni
* @since 2012-09-11
*/
function F_syncUserGroups($usrid, $grpids)
{
global $l, $db;
require_once '../config/tce_config.php';
$usrid = intval($usrid);
// select new group IDs
$newgrps = array();
if (is_string($grpids)) {
// comma separated list of group IDs
$newgrps = explode(',', $grpids);
array_walk($newgrps, 'intval');
$newgrps = array_unique($newgrps, SORT_NUMERIC);
} elseif ($grpids == 0) {
// all available groups
$sqlg = 'SELECT group_id FROM ' . K_TABLE_GROUPS . '';
if ($rg = F_db_query($sqlg, $db)) {
while ($mg = F_db_fetch_array($rg)) {
$newgrps[] = $mg['group_id'];
}
} else {
F_display_db_error();
}
} elseif ($grpids > 0) {
// single default group
$newgrps[] = intval($grpids);
}
if (empty($newgrps)) {
return;
}
// select existing group IDs
$usrgrps = array();
$sqlu = 'SELECT usrgrp_group_id FROM ' . K_TABLE_USERGROUP . ' WHERE usrgrp_user_id=' . $usrid . '';
if ($ru = F_db_query($sqlu, $db)) {
while ($mu = F_db_fetch_array($ru)) {
$usrgrps[] = $mu['usrgrp_group_id'];
}
} else {
F_display_db_error();
}
// extract missing groups
$diffgrps = array_values(array_diff($newgrps, $usrgrps));
// add missing groups
foreach ($diffgrps as $grpid) {
if ($grpid > 0) {
// add user to default user groups
$sql = 'INSERT INTO ' . K_TABLE_USERGROUP . ' (
usrgrp_user_id,
usrgrp_group_id
) VALUES (
\'' . $usrid . '\',
\'' . $grpid . '\'
)';
if (!($r = F_db_query($sql, $db))) {
F_display_db_error();
}
}
}
}
示例14: F_session_write
/**
* Insert or Update session.
* @param $key (string) session ID.
* @param $val (string) session data.
* @return resource database query result.
*/
function F_session_write($key, $val)
{
global $db;
if (!isset($db) or !$db) {
// workaround for PHP bug 41230
if (!($db = @F_db_connect(K_DATABASE_HOST, K_DATABASE_PORT, K_DATABASE_USER_NAME, K_DATABASE_USER_PASSWORD, K_DATABASE_NAME))) {
return;
}
}
$key = F_escape_sql($key);
$val = F_escape_sql($val);
$expiry = date(K_TIMESTAMP_FORMAT, time() + K_SESSION_LIFE);
// check if this session already exist on database
$sql = 'SELECT cpsession_id
FROM ' . K_TABLE_SESSIONS . '
WHERE cpsession_id=\'' . $key . '\'
LIMIT 1';
if ($r = F_db_query($sql, $db)) {
if ($m = F_db_fetch_array($r)) {
// SQL to update existing session
$sqlup = 'UPDATE ' . K_TABLE_SESSIONS . ' SET
cpsession_expiry=\'' . $expiry . '\',
cpsession_data=\'' . $val . '\'
WHERE cpsession_id=\'' . $key . '\'';
} else {
// SQL to insert new session
$sqlup = 'INSERT INTO ' . K_TABLE_SESSIONS . ' (
cpsession_id,
cpsession_expiry,
cpsession_data
) VALUES (
\'' . $key . '\',
\'' . $expiry . '\',
\'' . $val . '\'
)';
}
}
return F_db_query($sqlup, $db);
}
示例15: F_syncUserGroups
F_syncUserGroups($_SESSION['session_user_id'], $altusr['usrgrp_group_id']);
}
} elseif (!F_check_unique(K_TABLE_USERS, 'user_name=\'' . F_escape_sql($db, $_POST['xuser_name']) . '\'')) {
// the user name exist but the password is wrong
if ($altusr !== false) {
// resync the password
$sqlu = 'UPDATE ' . K_TABLE_USERS . ' SET
user_password=\'' . $xuser_password . '\'
WHERE user_name=\'' . F_escape_sql($db, $_POST['xuser_name']) . '\'';
if (!($ru = F_db_query($sqlu, $db))) {
F_display_db_error();
}
// get user data
$sqld = 'SELECT * FROM ' . K_TABLE_USERS . ' WHERE user_name=\'' . F_escape_sql($db, $_POST['xuser_name']) . '\' AND user_password=\'' . $xuser_password . '\'';
if ($rd = F_db_query($sqld, $db)) {
if ($md = F_db_fetch_array($rd)) {
// sets some user's session data
$_SESSION['session_user_id'] = $md['user_id'];
$_SESSION['session_user_name'] = $md['user_name'];
$_SESSION['session_user_ip'] = getNormalizedIP($_SERVER['REMOTE_ADDR']);
$_SESSION['session_user_level'] = $md['user_level'];
$_SESSION['session_user_firstname'] = urlencode($md['user_firstname']);
$_SESSION['session_user_lastname'] = urlencode($md['user_lastname']);
$_SESSION['session_last_visit'] = 0;
$_SESSION['session_test_login'] = '';
$logged = true;
if (K_USER_GROUP_RSYNC) {
// sync user groups
F_syncUserGroups($_SESSION['session_user_id'], $altusr['usrgrp_group_id']);
}
}