function viewretrieve($var)
{
    global $xoopsModuleConfig;
    if ($xoopsModuleConfig['site_user_auth'] == 1) {
        if ($ret = check_for_lock(basename(__FILE__), $username, $password)) {
            return $ret;
        }
        if (!checkright(basename(__FILE__), $username, $password)) {
            mark_for_lock(basename(__FILE__), $username, $password);
            return array('ErrNum' => 9, "ErrDesc" => 'No Permission for plug-in');
        }
    }
    global $xoopsDB;
    if (strlen($var['viewname']) > 0) {
        $tbl_id = get_tableid($var['viewname']);
    } elseif ($var['id'] > 0) {
        $tbl_id = $var['id'];
    } else {
        return array('ErrNum' => 2, "ErrDesc" => 'Table Name or Table ID not specified');
    }
    if (!validate($tbl_id, $var['data'], "allowretrieve")) {
        return array('ErrNum' => 4, "ErrDesc" => 'Not all fields are allowed retrieve');
    } else {
        $sql = "SELECT ";
        $sql_b .= "*,";
        if (strlen($var['clause']) > 0) {
            if (strpos(' ' . strtolower($var['clause']), 'union') > 0) {
                return array('ErrNum' => 8, "ErrDesc" => 'Union not accepted');
            }
            $sql_c .= 'WHERE ' . $var['clause'] . "";
        }
        global $xoopsModuleConfig;
        if ($xoopsModuleConfig['site_user_auth'] == 1) {
            if (!validateuser($var['username'], $var['password'])) {
                return false;
            }
        }
        //echo $sql." ".substr($sql_b,0,strlen($str_b)-1)." FROM ".$xoopsDB->prefix(get_viewname($tbl_id))." ".$sql_c;
        $rt = $xoopsDB->queryf($sql . " " . substr($sql_b, 0, strlen($str_b) - 1) . " FROM " . $xoopsDB->prefix(get_viewname($tbl_id)) . " " . $sql_c);
        if (!$xoopsDB->getRowsNum($rt)) {
            return array('ErrNum' => 3, "ErrDesc" => 'No Records Returned from Query');
        } else {
            $rtn = array();
            while ($row = $xoopsDB->fetchArray($rt)) {
                $rdata = array();
                foreach ($var['data'] as $data) {
                    $rdata[] = array("fieldname" => $data['field'], "value" => $row[$data['field']]);
                }
                $rtn[] = $rdata;
            }
        }
        return array("total_records" => $xoopsDB->getRowsNum($rt), "data" => $rtn);
    }
}
function create_view($viewdefs)
{
    global $dbhandle;
    global $ib_error, $lsql;
    $lsql = $viewdefs['source'];
    if ($viewdefs['check'] == 'yes') {
        $lsql .= "\nWITH CHECK OPTION";
    }
    if (DEBUG) {
        add_debug('lsql', __FILE__, __LINE__);
    }
    if (!@fbird_query($dbhandle, $lsql)) {
        $ib_error = fbird_errmsg();
    }
    return empty($ib_error) ? get_viewname($viewdefs['source']) : FALSE;
}
     $s_viewdefs = array('name' => $vname, 'source' => 'CREATE VIEW ' . $vname . ' (' . implode(', ', table_columns($vname)) . ")\nAS\n" . str_replace('WITH CHECK OPTION', '', $vsource), 'check' => stristr($vsource, 'WITH CHECK OPTION') !== FALSE ? 'yes' : 'no');
     $viewdefs = $s_viewdefs;
     $view_mod_flag = TRUE;
 }
 // modifying a View was canceled
 if (isset($_POST['acc_modview_cancel'])) {
     $s_viewdefs = array('name' => '', 'source' => '', 'check' => 'no');
 }
 // modify the View
 if (isset($_POST['acc_modview_doit'])) {
     $viewdefs['source'] = get_magic_quotes_gpc() ? stripslashes(trim($_POST['def_view_source'])) : $_POST['def_view_source'];
     $viewdefs['check'] = isset($_POST['def_view_check']) ? 'yes' : 'no';
     if (drop_view($s_viewdefs['name'])) {
         if (create_view($viewdefs)) {
             unset($s_tables[$s_viewdefs['name']]);
             $s_tables[get_viewname($viewdefs['source'])] = array('status' => 'close', 'is_view' => TRUE);
             $s_viewdefs = array('name' => '', 'source' => '', 'check' => 'no');
             $s_tables_valid = FALSE;
         } else {
             create_view($s_viewdefs);
             $view_mod_flag = TRUE;
         }
     }
 }
 // the Delete button
 if (isset($_POST['acc_view_del']) && isset($_POST['acc_delview_name']) && $_POST['acc_delview_name'] != '') {
     $dname = $_POST['acc_delview_name'];
     $deps = get_dependencies(OT_FIELD, $dname);
     if (count($deps) > 0) {
         $message = sprintf($MESSAGES['HAVE_DEPENDENCIES'], $acc_strings['View'], $dname, dependencies_string($deps));
     } else {