当前位置: 首页>>代码示例>>PHP>>正文


PHP F_empty_to_null函数代码示例

本文整理汇总了PHP中F_empty_to_null函数的典型用法代码示例。如果您正苦于以下问题:PHP F_empty_to_null函数的具体用法?PHP F_empty_to_null怎么用?PHP F_empty_to_null使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了F_empty_to_null函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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']) . ',';
//.........这里部分代码省略.........
开发者ID:BGCX261,项目名称:zjxt-svn-to-git,代码行数:101,代码来源:tce_import_xml_users.php

示例2: 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();
    }
}
开发者ID:jayadevn,项目名称:RackMap,代码行数:54,代码来源:tce_functions_objects.php

示例3: intval

				\'' . intval($_SESSION['session_user_id']) . '\',
				\'' . $test_score_threshold . '\',
				\'' . intval($test_random_questions_select) . '\',
				\'' . intval($test_random_questions_order) . '\',
				\'' . $test_questions_order_mode . '\',
				\'' . intval($test_random_answers_select) . '\',
				\'' . intval($test_random_answers_order) . '\',
				\'' . $test_answers_order_mode . '\',
				\'' . intval($test_comment_enabled) . '\',
				\'' . intval($test_menu_enabled) . '\',
				\'' . intval($test_noanswer_enabled) . '\',
				\'' . intval($test_mcma_radio) . '\',
				\'' . intval($test_repeatable) . '\',
				\'' . intval($test_mcma_partial_score) . '\',
				\'' . intval($test_logout_on_timeout) . '\',
				' . F_empty_to_null($test_password) . '
				)';
            if (!($r = F_db_query($sql, $db))) {
                F_display_db_error(false);
            } else {
                $test_id = F_db_insert_id($db, K_TABLE_TESTS, 'test_id');
            }
            // add authorized user's groups
            if (!empty($user_groups)) {
                foreach ($user_groups as $group_id) {
                    $sql = 'INSERT INTO ' . K_TABLE_TEST_GROUPS . ' (
						tstgrp_test_id,
						tstgrp_group_id
						) VALUES (
						\'' . $test_id . '\',
						\'' . intval($group_id) . '\'
开发者ID:dungvu,项目名称:tcexam,代码行数:31,代码来源:tce_edit_test.php

示例4: VALUES

				user_otpkey
				) VALUES (
				\'' . F_escape_sql($db, $user_regdate) . '\',
				\'' . F_escape_sql($db, $user_ip) . '\',
				\'' . F_escape_sql($db, $user_name) . '\',
				' . F_empty_to_null($user_email) . ',
				\'' . F_escape_sql($db, $user_password) . '\',
				' . F_empty_to_null($user_regnumber) . ',
				' . F_empty_to_null($user_firstname) . ',
				' . F_empty_to_null($user_lastname) . ',
				' . F_empty_to_null($user_birthdate) . ',
				' . F_empty_to_null($user_birthplace) . ',
				' . F_empty_to_null($user_ssn) . ',
				\'' . $usrlevel . '\',
				\'' . $user_verifycode . '\',
				' . F_empty_to_null($user_otpkey) . '
				)';
            if (!($r = F_db_query($sql, $db))) {
                F_display_db_error(false);
            } else {
                $user_id = F_db_insert_id($db, K_TABLE_USERS, 'user_id');
            }
            // add user's groups
            if (empty($user_groups)) {
                $user_groups = array(K_USRREG_GROUP);
            } elseif (!in_array(K_USRREG_GROUP, $user_groups)) {
                $user_groups[] = K_USRREG_GROUP;
            }
            foreach ($user_groups as $group_id) {
                $sql = 'INSERT INTO ' . K_TABLE_USERGROUP . ' (
					usrgrp_user_id,
开发者ID:dungvu,项目名称:tcexam,代码行数:31,代码来源:tce_user_registration.php

示例5: F_importServerObj

/**
 * Import the specifed server object.
 * @param $srv (array) array containing object data.
 * @return true in case of success, false otherwise
 */
function F_importServerObj($srv)
{
    global $l, $db;
    require_once '../config/tce_config.php';
    if (!isset($srv['serial']) or empty($srv['serial'])) {
        F_print_error('ERROR', 'missing serial');
        return false;
    }
    // get ID of the object with the same serial number
    $sql = 'SELECT obj_id FROM ' . K_TABLE_OBJECTS . ' WHERE obj_tag=\'' . F_escape_sql($srv['serial']) . '\' LIMIT 1';
    if ($r = F_db_query($sql, $db)) {
        if ($m = F_db_fetch_assoc($r)) {
            $obj_id = $m['obj_id'];
        } else {
            // this object do not exist.
            F_print_error('ERROR', $srv['serial']);
            return false;
        }
    } else {
        F_display_db_error(false);
        return false;
    }
    // attribute map
    $srvattrmap = array('hostname' => 66, 'os release' => 68, 'os type' => 67, 'kernel name' => 69, 'kernel release' => 70, 'kernel version' => 71, 'kernel architecture' => 72, 'product' => 17, 'uuid' => 26);
    // for each attribute
    foreach ($srvattrmap as $k => $v) {
        if (isset($srv[$k]) and strlen($srv[$k]) > 0) {
            $value = $srv[$k];
            if ($k == 'product' and isset($srv['manufacturer']) and !empty($srv['manufacturer'])) {
                $value = $srv['manufacturer'] . ' ' . $value;
            }
            // add or update attribute value
            $sqla = 'REPLACE INTO ' . K_TABLE_ATTRIBUTE_VALUES . ' (
				atv_obj_id,
				atv_atb_id,
				atv_value
				) VALUES (
				' . $obj_id . ',
				' . $v . ',
				\'' . F_escape_sql($value) . '\'
				)';
            if (!($ra = F_db_query($sqla, $db))) {
                F_display_db_error(false);
                return false;
            }
        }
    }
    // cpu attribute map
    $cpuattrmap = array('Socket Designation' => 92, 'Family' => 94, 'ID' => 93, 'Architecture' => 56, 'CPU op-mode(s)' => 83, 'Byte Order' => 84, 'Thread(s) per core' => 85, 'Core(s) per socket' => 55, 'Vendor ID' => 86, 'CPU family' => 87, 'Model' => 88, 'Stepping' => 89, 'CPU MHz' => 25, 'Virtualization' => 90, 'L1d cache' => 81, 'L1i cache' => 82, 'L1 cache' => 57, 'L2 cache' => 58, 'L3 cache' => 59);
    // cpu
    if (isset($srv['dmi']['Processor Information']) and !empty($srv['dmi']['Processor Information'])) {
        $cpucount = 0;
        foreach ($srv['dmi']['Processor Information'] as $cpu) {
            ++$cpucount;
            $cpuname = sprintf('CPU%02d', $cpucount);
            // check if CPU exist
            $sql = 'SELECT obj_id FROM ' . K_TABLE_OBJECTS . ', ' . K_TABLE_OBJECTS_MAP . '
				WHERE obj_id=omp_child_obj_id AND omp_parent_obj_id=' . $obj_id . ' AND obj_obt_id=58 AND obj_name=\'' . $cpuname . '\'
				ORDER BY obj_name';
            if ($r = F_db_query($sql, $db)) {
                if ($m = F_db_fetch_assoc($r)) {
                    // update existing object
                    $cpu_obj_id = $m['obj_id'];
                } else {
                    // create new object
                    $sqlo = '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 (
						58,
						\'' . $cpuname . '\',
						' . F_empty_to_null('') . ',
						' . F_empty_to_null('') . ',
						' . F_empty_to_null('') . ',
						' . F_zero_to_null(0) . ',
						' . F_zero_to_null(0) . ',
						' . F_zero_to_null(0) . '
						)';
                    if (!($ro = F_db_query($sqlo, $db))) {
                        F_display_db_error(false);
                        return false;
                    } else {
                        $cpu_obj_id = F_db_insert_id($db, K_TABLE_OBJECTS, 'obj_id');
                    }
                    // set object map
                    $sqlm = 'INSERT INTO ' . K_TABLE_OBJECTS_MAP . ' (
						omp_parent_obj_id,
						omp_child_obj_id
						) VALUES (
//.........这里部分代码省略.........
开发者ID:jayadevn,项目名称:RackMap,代码行数:101,代码来源:tce_import_getos.php

示例6: F_print_error

        // Add
        if ($formstatus = F_check_form_fields()) {
            // check submitted form fields
            // check if name is unique
            if (!F_check_unique(K_TABLE_CABLE_TYPES, 'cbt_name=\'' . F_escape_sql($cbt_name) . '\'')) {
                F_print_error('WARNING', $l['m_duplicate_name']);
                $formstatus = FALSE;
                F_stripslashes_formfields();
                break;
            }
            $sql = 'INSERT INTO ' . K_TABLE_CABLE_TYPES . ' (
				cbt_name,
				cbt_description
				) VALUES (
				\'' . F_escape_sql($cbt_name) . '\',
				' . F_empty_to_null($cbt_description) . '
				)';
            if (!($r = F_db_query($sql, $db))) {
                F_display_db_error(false);
            } else {
                $cbt_id = F_db_insert_id($db, K_TABLE_CABLE_TYPES, 'cbt_id');
            }
        }
        break;
    case 'clear':
        // Clear form fields
        $cbt_name = '';
        $cbt_description = '';
        break;
    default:
        break;
开发者ID:jayadevn,项目名称:RackMap,代码行数:31,代码来源:tce_edit_cable_types.php

示例7: F_print_error

            // check if name is unique
            if (!F_check_unique(K_TABLE_SUBJECTS, 'subject_name=\'' . F_escape_sql($db, $subject_name) . '\' AND subject_module_id=' . $subject_module_id . '')) {
                F_print_error('WARNING', $l['m_duplicate_name']);
                $formstatus = FALSE;
                F_stripslashes_formfields();
                break;
            }
            $sql = 'INSERT INTO ' . K_TABLE_SUBJECTS . ' (
				subject_name,
				subject_description,
				subject_enabled,
				subject_user_id,
				subject_module_id
				) VALUES (
				\'' . F_escape_sql($db, $subject_name) . '\',
				' . F_empty_to_null($subject_description) . ',
				\'' . intval($subject_enabled) . '\',
				\'' . intval($_SESSION['session_user_id']) . '\',
				' . $subject_module_id . '
				)';
            if (!($r = F_db_query($sql, $db))) {
                F_display_db_error(false);
            } else {
                $subject_id = F_db_insert_id($db, K_TABLE_SUBJECTS, 'subject_id');
            }
        }
        break;
    case 'clear':
        // Clear form fields
        $subject_name = '';
        $subject_description = '';
开发者ID:dungvu,项目名称:tcexam,代码行数:31,代码来源:tce_edit_subject.php

示例8: VALUES

				user_birthdate,
				user_birthplace,
				user_ssn,
				user_level
				) VALUES (
				\'' . F_escape_sql($user_regdate) . '\',
				\'' . F_escape_sql($user_ip) . '\',
				\'' . F_escape_sql($user_name) . '\',
				' . F_empty_to_null($user_email) . ',
				\'' . F_escape_sql($user_password) . '\',
				' . F_empty_to_null($user_regnumber) . ',
				' . F_empty_to_null($user_firstname) . ',
				' . F_empty_to_null($user_lastname) . ',
				' . F_empty_to_null($user_birthdate) . ',
				' . F_empty_to_null($user_birthplace) . ',
				' . F_empty_to_null($user_ssn) . ',
				\'' . $user_level . '\'
				)';
            if (!($r = F_db_query($sql, $db))) {
                F_display_db_error(false);
            } else {
                $user_id = F_db_insert_id($db, K_TABLE_USERS, 'user_id');
            }
            // add user's groups
            if (!empty($user_groups)) {
                foreach ($user_groups as $group_id) {
                    if (F_isAuthorizedEditorForGroup($group_id)) {
                        $sql = 'INSERT INTO ' . K_TABLE_USERGROUP . ' (
							usrgrp_user_id,
							usrgrp_group_id
							) VALUES (
开发者ID:BGCX261,项目名称:zjxt-svn-to-git,代码行数:31,代码来源:tce_edit_user.php

示例9: VALUES

            $sql = 'INSERT INTO ' . K_TABLE_ANSWERS . ' (
				answer_question_id,
				answer_description,
				answer_explanation,
				answer_isright,
				answer_enabled,
				answer_position,
				answer_keyboard_key
				) VALUES (
				' . $answer_question_id . ',
				\'' . F_escape_sql($answer_description) . '\',
				' . F_empty_to_null($answer_explanation) . ',
				\'' . $answer_isright . '\',
				\'' . $answer_enabled . '\',
				' . F_zero_to_null($answer_position) . ',
				' . F_empty_to_null($answer_keyboard_key) . '
				)';
            if (!($r = F_db_query($sql, $db))) {
                F_display_db_error(false);
                F_db_query('ROLLBACK', $db);
                // rollback transaction
            } else {
                $answer_id = F_db_insert_id($db, K_TABLE_ANSWERS, 'answer_id');
            }
            $sql = 'COMMIT';
            if (!($r = F_db_query($sql, $db))) {
                F_display_db_error(false);
                break;
            }
        }
        break;
开发者ID:BGCX261,项目名称:zjxt-svn-to-git,代码行数:31,代码来源:tce_edit_answer.php

示例10: F_print_error

            if (!F_check_unique(K_TABLE_DATACENTERS, 'dcn_name=\'' . F_escape_sql($dcn_name) . '\'')) {
                F_print_error('WARNING', $l['m_duplicate_name']);
                $formstatus = FALSE;
                F_stripslashes_formfields();
                break;
            }
            $sql = 'INSERT INTO ' . K_TABLE_DATACENTERS . ' (
				dcn_name,
				dcn_description,
				dcn_website_url,
				dcn_map_url
				) VALUES (
				\'' . F_escape_sql($dcn_name) . '\',
				' . F_empty_to_null($dcn_description) . ',
				' . F_empty_to_null($dcn_website_url) . ',
				' . F_empty_to_null($dcn_map_url) . '
				
				)';
            if (!($r = F_db_query($sql, $db))) {
                F_display_db_error(false);
            } else {
                $dcn_id = F_db_insert_id($db, K_TABLE_DATACENTERS, 'dcn_id');
            }
            // add default permission for non administrators
            if ($userlevel < K_AUTH_ADMINISTRATOR and empty($perms)) {
                foreach ($user_groups as $grp) {
                    $perms[$grp] = 15;
                    // read + add + update + delete
                }
            }
            // insert groups permissions
开发者ID:jayadevn,项目名称:RackMap,代码行数:31,代码来源:tce_edit_datacenters.php

示例11: F_print_error

                F_print_error('WARNING', $l['m_duplicate_name']);
                $formstatus = FALSE;
                F_stripslashes_formfields();
                break;
            }
            $sql = 'INSERT INTO ' . K_TABLE_SUITES . ' (
				sts_dcn_id,
				sts_name,
				sts_description,
				sts_floor,
				sts_width,
				sts_height
				) VALUES (
				' . $dcn_id . ',
				\'' . F_escape_sql($sts_name) . '\',
				' . F_empty_to_null($sts_description) . ',
				' . $sts_floor . ',
				' . $sts_width . ',
				' . $sts_height . '
				)';
            if (!($r = F_db_query($sql, $db))) {
                F_display_db_error(false);
            } else {
                $sts_id = F_db_insert_id($db, K_TABLE_SUITES, 'sts_id');
            }
            // add default permission for non administrators
            if ($userlevel < K_AUTH_ADMINISTRATOR and empty($perms)) {
                foreach ($user_groups as $grp) {
                    $perms[$grp] = 15;
                    // read + add + update + delete
                }
开发者ID:jayadevn,项目名称:RackMap,代码行数:31,代码来源:tce_edit_suites.php

示例12: VALUES

            }
            $sql = 'INSERT INTO ' . K_TABLE_RACKS . ' (
				rck_sts_id,
				rck_name,
				rck_description,
				rck_label,
				rck_tag,
				rck_height,
				rck_position_x,
				rck_position_y
				) VALUES (
				' . $sts_id . ',
				\'' . F_escape_sql($rck_name) . '\',
				' . F_empty_to_null($rck_description) . ',
				' . F_empty_to_null($rck_label) . ',
				' . F_empty_to_null($rck_tag) . ',
				' . $rck_height . ',
				' . $rck_position_x . ',
				' . $rck_position_y . '
				)';
            if (!($r = F_db_query($sql, $db))) {
                F_display_db_error(false);
            } else {
                $rck_id = F_db_insert_id($db, K_TABLE_RACKS, 'rck_id');
            }
            // add default permission for non administrators
            if ($userlevel < K_AUTH_ADMINISTRATOR and empty($perms)) {
                foreach ($user_groups as $grp) {
                    $perms[$grp] = 15;
                    // read + add + update + delete
                }
开发者ID:jayadevn,项目名称:RackMap,代码行数:31,代码来源:tce_edit_racks.php

示例13: F_print_error

            // check submitted form fields
            // check if name is unique
            if (!F_check_unique(K_TABLE_MANUFACTURES, 'mnf_name=\'' . F_escape_sql($mnf_name) . '\'')) {
                F_print_error('WARNING', $l['m_duplicate_name']);
                $formstatus = FALSE;
                F_stripslashes_formfields();
                break;
            }
            $sql = 'INSERT INTO ' . K_TABLE_MANUFACTURES . ' (
				mnf_name,
				mnf_url,
				mnf_description
				) VALUES (
				\'' . F_escape_sql($mnf_name) . '\',
				' . F_empty_to_null($mnf_url) . ',
				' . F_empty_to_null($mnf_description) . '
				)';
            if (!($r = F_db_query($sql, $db))) {
                F_display_db_error(false);
            } else {
                $mnf_id = F_db_insert_id($db, K_TABLE_MANUFACTURES, 'mnf_id');
            }
            // add mac prefixes
            foreach ($macs as $k => $v) {
                $sql = 'INSERT INTO ' . K_TABLE_MANUFACTURES_MAC . ' (
					mac_mnf_id,
					mac_mac
					) VALUES (
					' . $mnf_id . ',
					\'' . F_escape_sql($v) . '\'
					)';
开发者ID:jayadevn,项目名称:RackMap,代码行数:31,代码来源:tce_edit_manufacturers.php

示例14: F_TSVQuestionImporter

/**
 * Import questions from TSV file (tab delimited text).
 * The format of TSV is the same obtained by exporting data from TCExam interface.
 * @param $tsvfile (string) TSV (tab delimited text) file name
 * @return boolean TRUE in case of success, FALSE otherwise
 */
function F_TSVQuestionImporter($tsvfile)
{
    global $l, $db;
    require_once '../config/tce_config.php';
    require_once '../../shared/code/tce_functions_auth_sql.php';
    $qtype = array('S' => 1, 'M' => 2, 'T' => 3, 'O' => 4);
    // get file content as array
    $tsvrows = file($tsvfile, FILE_IGNORE_NEW_LINES);
    // array of TSV lines
    if ($tsvrows === FALSE) {
        return FALSE;
    }
    $current_module_id = 0;
    $current_subject_id = 0;
    $current_question_id = 0;
    $current_answer_id = 0;
    $questionhash = array();
    // for each row
    while (list($item, $rowdata) = each($tsvrows)) {
        // get user data into array
        $qdata = explode("\t", $rowdata);
        switch ($qdata[0]) {
            case 'M':
                // MODULE
                $current_module_id = 0;
                if (!isset($qdata[2]) or empty($qdata[2])) {
                    break;
                }
                $module_enabled = intval($qdata[1]);
                $module_name = F_escape_sql($db, F_tsv_to_text($qdata[2]), false);
                // check if this module already exist
                $sql = 'SELECT module_id
					FROM ' . K_TABLE_MODULES . '
					WHERE module_name=\'' . $module_name . '\'
					LIMIT 1';
                if ($r = F_db_query($sql, $db)) {
                    if ($m = F_db_fetch_array($r)) {
                        // get existing module ID
                        if (!F_isAuthorizedUser(K_TABLE_MODULES, 'module_id', $m['module_id'], 'module_user_id')) {
                            // unauthorized user
                            $current_module_id = 0;
                        } else {
                            $current_module_id = $m['module_id'];
                        }
                    } else {
                        // insert new module
                        $sql = 'INSERT INTO ' . K_TABLE_MODULES . ' (
							module_name,
							module_enabled,
							module_user_id
							) VALUES (
							\'' . $module_name . '\',
							\'' . $module_enabled . '\',
							\'' . $_SESSION['session_user_id'] . '\'
							)';
                        if (!($r = F_db_query($sql, $db))) {
                            F_display_db_error();
                        } else {
                            // get new module ID
                            $current_module_id = F_db_insert_id($db, K_TABLE_MODULES, 'module_id');
                        }
                    }
                } else {
                    F_display_db_error();
                }
                break;
            case 'S':
                // SUBJECT
                $current_subject_id = 0;
                if ($current_module_id == 0) {
                    return;
                }
                if (!isset($qdata[2]) or empty($qdata[2])) {
                    break;
                }
                $subject_enabled = intval($qdata[1]);
                $subject_name = F_escape_sql($db, F_tsv_to_text($qdata[2]), false);
                $subject_description = '';
                if (isset($qdata[3])) {
                    $subject_description = F_empty_to_null(F_tsv_to_text($qdata[3]));
                }
                // check if this subject already exist
                $sql = 'SELECT subject_id
					FROM ' . K_TABLE_SUBJECTS . '
					WHERE subject_name=\'' . $subject_name . '\'
						AND subject_module_id=' . $current_module_id . '
					LIMIT 1';
                if ($r = F_db_query($sql, $db)) {
                    if ($m = F_db_fetch_array($r)) {
                        // get existing subject ID
                        $current_subject_id = $m['subject_id'];
                    } else {
                        // insert new subject
                        $sql = 'INSERT INTO ' . K_TABLE_SUBJECTS . ' (
//.........这里部分代码省略.........
开发者ID:dungvu,项目名称:tcexam,代码行数:101,代码来源:tce_import_questions.php

示例15: F_updateQuestionLog


//.........这里部分代码省略.........
                        }
                        break;
                    case 4:
                        // ORDER
                        if (isset($answer_id[$m['logansw_answer_id']]) and $answer_id[$m['logansw_answer_id']] > 0) {
                            // selected
                            $unanswered = false;
                            $answer_id[$m['logansw_answer_id']] = intval($answer_id[$m['logansw_answer_id']]);
                            if ($answer_id[$m['logansw_answer_id']] == $m['answer_position']) {
                                $answer_score += $question_right_score;
                            } else {
                                $answer_score += $question_wrong_score;
                            }
                            if ($answer_id[$m['logansw_answer_id']] != $m['logansw_position']) {
                                $answer_changed = true;
                            }
                            $sqlu .= ' logansw_position=' . $answer_id[$m['logansw_answer_id']] . ', logansw_selected=1';
                        } else {
                            // unanswered
                            $answer_score += $question_unanswered_score;
                            if ($m['logansw_position'] > 0) {
                                $answer_changed = true;
                            }
                            $sqlu .= ' logansw_selected=-1, logansw_position=0';
                        }
                        break;
                }
                // end of switch
                $sqlu .= ' WHERE logansw_testlog_id=' . $testlog_id . ' AND logansw_answer_id=' . $m['logansw_answer_id'] . '';
                if (!($ru = F_db_query($sqlu, $db))) {
                    F_display_db_error();
                    return false;
                }
            }
            if ($question_type > 1) {
                // normalize score
                if (F_getBoolean($testdata['test_mcma_partial_score'])) {
                    // use partial scoring for MCMA and ORDER questions
                    $answer_score = round($answer_score / $num_answers, 3);
                } else {
                    // all-or-nothing points
                    if ($answer_score >= $question_right_score * $num_answers) {
                        // right
                        $answer_score = $question_right_score;
                    } elseif ($answer_score == $question_unanswered_score * $num_answers) {
                        // unanswered
                        $answer_score = $question_unanswered_score;
                    } else {
                        // wrong
                        $answer_score = $question_wrong_score;
                    }
                }
            }
        } else {
            F_display_db_error();
            return false;
        }
    }
    // update log if answer is changed
    if ($answer_changed or $oldtext != $answer_text) {
        if (strlen($answer_text) > 0) {
            $unanswered = false;
            $answer_score = 'NULL';
            // check exact answers score
            $sql = 'SELECT *
				FROM ' . K_TABLE_ANSWERS . '
				WHERE answer_question_id=' . $question_id . '
					AND answer_enabled=\'1\'
					AND answer_isright=\'1\'';
            if ($r = F_db_query($sql, $db)) {
                while ($m = F_db_fetch_array($r)) {
                    if (strcasecmp(trim($answer_text), $m['answer_description']) == 0) {
                        $answer_score += $question_right_score;
                        break;
                    }
                }
            } else {
                F_display_db_error();
                return false;
            }
        }
        if ($unanswered) {
            $change_time = '';
        } else {
            $change_time = date(K_TIMESTAMP_FORMAT);
        }
        $sqlu = 'UPDATE ' . K_TABLE_TESTS_LOGS . ' SET';
        $sqlu .= ' testlog_answer_text=' . F_empty_to_null($answer_text) . ',';
        $sqlu .= ' testlog_score=' . $answer_score . ',';
        $sqlu .= ' testlog_change_time=' . F_empty_to_null($change_time) . ',';
        $sqlu .= ' testlog_reaction_time=' . intval($reaction_time) . ',';
        $sqlu .= ' testlog_user_ip=\'' . getNormalizedIP($_SERVER['REMOTE_ADDR']) . '\'';
        $sqlu .= ' WHERE testlog_id=' . $testlog_id . '';
        if (!($ru = F_db_query($sqlu, $db))) {
            F_display_db_error();
            return false;
        }
    }
    return true;
}
开发者ID:BGCX261,项目名称:zjxt-svn-to-git,代码行数:101,代码来源:tce_functions_test.php


注:本文中的F_empty_to_null函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。