</table>
    </div>
    <h3><?php 
echo Language::string(696);
?>
</h3>
    <div>
        <table class='fullWidth'>
            <?php 
$count = 0;
$sql = "SELECT `" . Ini::$db_master_name . "`.`" . RDocFunction::get_mysql_table() . "`.`id`,\r\n                            `" . Ini::$db_master_name . "`.`" . UserFunction::get_mysql_table() . "`.`id`\r\n                            FROM `" . Ini::$db_master_name . "`.`" . UserFunction::get_mysql_table() . "` \r\n                            LEFT JOIN `" . Ini::$db_master_name . "`.`" . RDocFunction::get_mysql_table() . "` \r\n                                ON `" . Ini::$db_master_name . "`.`" . RDocFunction::get_mysql_table() . "`.`id`=`" . Ini::$db_master_name . "`.`" . UserFunction::get_mysql_table() . "`.`RDocFunction_id`\r\n                            WHERE `" . Ini::$db_master_name . "`.`" . UserFunction::get_mysql_table() . "`.`User_id`=" . $logged_user->id . "\r\n                            ORDER BY `" . Ini::$db_master_name . "`.`" . RDocFunction::get_mysql_table() . "`.`name` ASC";
$z = mysql_query($sql);
while ($r = mysql_fetch_array($z)) {
    $func = RDocFunction::from_mysql_id($r[0]);
    $count++;
    $doc = RDoc::from_mysql_id($func->RDoc_id);
    $lib = RDocLibrary::from_mysql_id($func->RDocLibrary_id);
    $doc_html = "";
    if ($doc != null) {
        $doc_html = $doc->HTML;
    }
    ?>
                <tr onmouseover='Test.uiMouseOverFunctionToolbarTr(<?php 
    echo $count;
    ?>
)'>
                    <td class='tdFunctionToolbarIcon'>
                        <span class="spanIcon ui-icon ui-icon-help tooltipDocDescription" title="<?php 
    echo Language::string(708);
    ?>
" onclick='Test.uiDocDialog(Test.getDocContent($(this).next().val()))'></span>
 public function get_RDoc()
 {
     return RDoc::from_mysql_id($this->RDoc_id);
 }
 Copyright (C) 2011-2013, The Psychometrics Centre, Cambridge University

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; version 2
 of the License, and not any of the later versions.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/
if (!isset($ini)) {
    require_once '../../Ini.php';
    $ini = new Ini();
}
$logged_user = User::get_logged_user();
if ($logged_user == null) {
    echo json_encode(array());
    exit;
}
$sql = "SELECT `" . Ini::$db_master_name . "`.`" . RDoc::get_mysql_table() . "`.`HTML`\r\n    FROM `" . Ini::$db_master_name . "`.`" . RDoc::get_mysql_table() . "`\r\n    LEFT JOIN `" . Ini::$db_master_name . "`.`" . RDocFunction::get_mysql_table() . "` ON `" . Ini::$db_master_name . "`.`" . RDocFunction::get_mysql_table() . "`.`RDoc_id` = `" . Ini::$db_master_name . "`.`" . RDoc::get_mysql_table() . "`.`id`\r\n    WHERE `" . Ini::$db_master_name . "`.`" . RDocFunction::get_mysql_table() . "`.`name` = '" . $_POST['func'] . "'";
$z = mysql_query($sql);
while ($r = mysql_fetch_array($z)) {
    echo json_encode(array("html" => $r[0]));
    break;
}
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/
if (!isset($ini)) {
    require_once __DIR__ . '/../Ini.php';
    $ini = new Ini();
}
$path = Ini::$path_data . session_id() . ".Rc";
$sql = sprintf("TRUNCATE TABLE `%s`.`%s`", Ini::$db_master_name, RDoc::get_mysql_table());
mysql_query($sql);
$sql = sprintf("TRUNCATE TABLE `%s`.`%s`", Ini::$db_master_name, RDocLibrary::get_mysql_table());
mysql_query($sql);
$sql = sprintf("TRUNCATE TABLE `%s`.`%s`", Ini::$db_master_name, RDocFunction::get_mysql_table());
mysql_query($sql);
include __DIR__ . "/../SETTINGS.php";
$code = "\r\n        library(RMySQL)\r\n        library(tools)\r\n        unlink('{$path}')\r\n        drv <- dbDriver('MySQL')\r\n        con <- dbConnect(drv, user = '******', password = '******', dbname = '{$db_master_name}', host = '{$db_host}', port = {$db_port}, client.flag=CLIENT_MULTI_STATEMENTS)\r\n        dbSendQuery(con,statement = 'SET NAMES \"utf8\";')\r\n        dbSendQuery(con,statement = 'SET time_zone=\"{$mysql_timezone}\";')\r\n            \r\n        adm <- c()\r\n        for(package in sort(.packages(T))){\r\n\r\n            dbSendQuery(con,paste('INSERT INTO `RDocLibrary` SET `name`=\"',package,'\" ; SELECT last_insert_id();',sep=''))\r\n            rs1 <- dbNextResult(con)\r\n            lid <- fetch(rs1, n=-1)[1,1]\r\n            library(package,character.only=T)\r\n            db <- Rd_db(package)\r\n\r\n            for(doc in db){\r\n                fileConn<-file('{$path}',open='a+')\r\n                tools::Rd2HTML(doc,out=fileConn)\r\n                HTML <- dbEscapeStrings(con,paste(readLines(fileConn),collapse='\n'))\r\n                dbSendQuery(con,paste('INSERT INTO `RDoc` SET `HTML`=\"',HTML,'\"; SELECT last_insert_id();',sep=''))\r\n                rs2 <- dbNextResult(con)\r\n                did <- fetch(rs2, n=-1)[1,1]\r\n                unlink('{$path}')\r\n\r\n                aliases <- tools:::.Rd_get_metadata(x=doc,kind='alias')\r\n                sql <- 'INSERT INTO `RDocFunction` (`name`,`RDocLibrary_id`,`RDoc_id`) VALUES '\r\n                first <- T\r\n                insert <- F\r\n                for(alias in aliases) {\r\n                    if(!grepl('^[a-zA-Z0-9_.]*\$',alias,perl=T) || alias %in% adm || !exists(alias) || !is.function(get(alias))){\r\n                        next\r\n                    }\r\n                    adm <- c(adm,alias)\r\n                    if(!first) {\r\n                        sql <- paste(sql,',',sep='')\r\n                    }\r\n                    alias <- dbEscapeStrings(con,alias)\r\n                    sql <- paste(sql,'(\"',alias,'\", \"',lid,'\", \"',did,'\") ',sep='')\r\n                    first <- F\r\n                    insert <- T\r\n                }\r\n                if(insert){\r\n                    dbSendQuery(con,sql)\r\n                }\r\n            }\r\n        }\r\n        ";
$fh = fopen($path, "w");
fwrite($fh, $code);
fclose($fh);
$rscript_path = Ini::$path_r_script;
`{$rscript_path} {$path}`;
if (file_exists($path)) {
    unlink($path);
}