예제 #1
0
function gen_sql_user_list(&$sql, &$tpl, $user_id, $db_id)
{
    $first_passed = TRUE;
    $user_found = FALSE;
    $oldrs_name = '';
    $userlist = get_sqluser_list_of_current_db($sql, $db_id);
    $dmn_id = get_user_domain_id($sql, $user_id);
    // Lets select all sqlusers of the current domain except the users of the current database
    $query = "SELECT t1.sqlu_name, t1.sqlu_id\r\n\t          FROM  sql_user as t1, sql_database as t2\r\n              WHERE  t1.sqld_id = t2.sqld_id AND t2.domain_id = ? AND t1.sqld_id  <> ? ORDER BY t1.sqlu_name";
    $rs = exec_query($sql, $query, array($dmn_id, $db_id));
    while (!$rs->EOF) {
        // Checks if it's the first element of the combobox and set it as selected
        if ($first_passed) {
            $select = "SELECTED";
            $first_passed = FALSE;
        } else {
            $select = '';
        }
        // 1. Compares the sqluser name with the record before (Is set as '' at the first time, see above)
        // 2. Compares the sqluser name with the userlist of the current database
        if ($oldrs_name != $rs->fields['sqlu_name'] && @(!in_array($rs->fields['sqlu_name'], $userlist))) {
            $user_found = TRUE;
            $oldrs_name = $rs->fields['sqlu_name'];
            $tpl->assign(array('SQLUSER_ID' => $rs->fields['sqlu_id'], 'SQLUSER_SELECTED' => $select, 'SQLUSER_NAME' => $rs->fields['sqlu_name']));
            $tpl->parse('SQLUSER_LIST', '.sqluser_list');
        }
        $rs->MoveNext();
    }
    // Lets hide the combobox in case there are no other sqlusers
    if (!$user_found) {
        $tpl->assign('SHOW_SQLUSER_LIST', '');
        return FALSE;
    } else {
        return TRUE;
    }
}
예제 #2
0
/**
 * @param EasySCP_Database $sql
 * @param EasySCP_TemplateEngine $tpl
 * @param int $user_id
 * @param int $db_id
 * @return bool
 */
function gen_sql_user_list($sql, $tpl, $user_id, $db_id)
{
    $cfg = EasySCP_Registry::get('Config');
    $first_passed = true;
    $user_found = false;
    $oldrs_name = '';
    $userlist = get_sqluser_list_of_current_db($sql, $db_id);
    $dmn_id = get_user_domain_id($user_id);
    // Let's select all sqlusers of the current domain except the users of the current database
    $query = "\n\t\tSELECT\n\t\t\tt1.`sqlu_name`,\n\t\t\tt1.`sqlu_id`\n\t\tFROM\n\t\t\t`sql_user` AS t1,\n\t\t\t`sql_database` AS t2\n\t\tWHERE\n\t\t\tt1.`sqld_id` = t2.`sqld_id`\n\t\t\tAND\n\t\t\tt2.`domain_id` = ?\n\t\tAND\n\t\t\tt1.`sqld_id` <> ?\n\t\tORDER BY\n\t\t\tt1.`sqlu_name`\n\t";
    $rs = exec_query($sql, $query, array($dmn_id, $db_id));
    while (!$rs->EOF) {
        // Checks if it's the first element of the combobox and set it as selected
        if ($first_passed) {
            $select = $cfg->HTML_SELECTED;
            $first_passed = false;
        } else {
            $select = '';
        }
        // 1. Compares the sqluser name with the record before (Is set as '' at the first time, see above)
        // 2. Compares the sqluser name with the userlist of the current database
        if ($oldrs_name != $rs->fields['sqlu_name'] && @(!in_array($rs->fields['sqlu_name'], $userlist))) {
            $user_found = true;
            $oldrs_name = $rs->fields['sqlu_name'];
            $tpl->append(array('SQLUSER_ID' => $rs->fields['sqlu_id'], 'SQLUSER_SELECTED' => $select, 'SQLUSER_NAME' => tohtml($rs->fields['sqlu_name'])));
        }
        $rs->moveNext();
    }
    // Show the combobox in case there are other sqlusers
    if ($user_found) {
        $tpl->assign('SHOW_SQLUSER_LIST', true);
        return true;
    } else {
        return false;
    }
}