Example #1
0
     //Get data from tables FUNCTIONS and populate new ROLES tables
     $rows = mysqli_query($dbTmp, "SELECT * FROM " . $_SESSION['tbl_prefix'] . "functions");
     while ($reccord = mysqli_fetch_array($rows)) {
         //Add new role title
         mysqli_query($dbTmp, "INSERT INTO " . $_SESSION['tbl_prefix'] . "roles_title\n                        VALUES (\n                            '" . $reccord['id'] . "',\n                            '" . $reccord['title'] . "'\n                       )");
         //Add each folder in roles_values
         foreach (explode(';', $reccord['groupes_visibles']) as $folderId) {
             if (!empty($folderId)) {
                 mysqli_query($dbTmp, "INSERT INTO " . $_SESSION['tbl_prefix'] . "roles_values\n                                VALUES (\n                                '" . $reccord['id'] . "',\n                                '" . $folderId . "'\n                               )");
             }
         }
     }
     //Now alter table roles_title in order to create a primary index
     mysqli_query($dbTmp, "ALTER TABLE `" . $_SESSION['tbl_prefix'] . "roles_title`\n                    ADD PRIMARY KEY(`id`)");
     mysqli_query($dbTmp, "ALTER TABLE `" . $_SESSION['tbl_prefix'] . "roles_title`\n                    CHANGE `id` `id` INT(12) NOT null AUTO_INCREMENT ");
     addColumnIfNotExist($_SESSION['tbl_prefix'] . "roles_title", "allow_pw_change", "TINYINT(1) NOT null DEFAULT '0'");
     //Drop old table
     mysqli_query($dbTmp, "DROP TABLE " . $_SESSION['tbl_prefix'] . "functions");
     echo 'document.getElementById("tbl_9").innerHTML = ' . '"<img src=\\"images/tick.png\\">";';
 } elseif ($tableFunctionExists == false) {
     echo 'document.getElementById("tbl_9").innerHTML = ' . '"<img src=\\"images/tick.png\\">";';
 } else {
     echo 'document.getElementById("res_step4").innerHTML = ' . '"An error appears on tables ROLES creation!";';
     echo 'document.getElementById("tbl_9").innerHTML = ' . '"<img src=\\"images/exclamation-red.png\\">";';
     echo 'document.getElementById("loader").style.display = "none";';
     mysqli_close($dbTmp);
     break;
 }
 ## TABLE KB
 $res = mysqli_query($dbTmp, "CREATE TABLE IF NOT EXISTS `" . $_SESSION['tbl_prefix'] . "kb` (\n                `id` int(12) NOT null AUTO_INCREMENT,\n                `category_id` int(12) NOT NULL,\n                `label` varchar(200) NOT NULL,\n                `description` text NOT NULL,\n                `author_id` int(12) NOT NULL,\n                `anyone_can_modify` tinyint(1) NOT null DEFAULT '0',\n                PRIMARY KEY (`id`)\n                );");
 if ($res) {
// add field timestamp to cache table
$res = addColumnIfNotExist($_SESSION['tbl_prefix'] . "cache", "timestamp", "VARCHAR(50) NOT NULL");
if ($res === false) {
    echo '[{"finish":"1", "msg":"", "error":"An error appears when adding field Timestamp to table Cache! ' . mysqli_error($dbTmp) . '!"}]';
    mysqli_close($dbTmp);
    exit;
}
// add field url to cache table
$res = addColumnIfNotExist($_SESSION['tbl_prefix'] . "cache", "url", "VARCHAR(500) NOT NULL DEFAULT '0'");
if ($res === false) {
    echo '[{"finish":"1", "msg":"", "error":"An error appears when adding field Url to table Cache! ' . mysqli_error($dbTmp) . '!"}]';
    mysqli_close($dbTmp);
    exit;
}
// add field can_manage_all_users to users table
$res = addColumnIfNotExist($_SESSION['tbl_prefix'] . "users", "can_manage_all_users", "tinyint(1) NOT NULL DEFAULT '0'");
if ($res === false) {
    echo '[{"finish":"1", "msg":"", "error":"An error appears when adding field can_manage_all_users to table Users! ' . mysqli_error($dbTmp) . '!"}]';
    mysqli_close($dbTmp);
    exit;
}
// check that API doesn't exist
$tmp = mysqli_fetch_row(mysqli_query($dbTmp, "SELECT COUNT(*) FROM `" . $_SESSION['tbl_prefix'] . "users` WHERE id = '" . API_USER_ID . "'"));
if ($tmp[0] == 0 || empty($tmp[0])) {
    mysqli_query($dbTmp, "INSERT INTO `" . $_SESSION['tbl_prefix'] . "users` (`id`, `login`, `read_only`) VALUES ('" . API_USER_ID . "', 'API', '1')");
}
// check that SYSLOG doesn't exist
$tmp = mysqli_fetch_row(mysqli_query($dbTmp, "SELECT COUNT(*) FROM `" . $_SESSION['tbl_prefix'] . "misc` WHERE type = 'admin' AND intitule = 'syslog_enable'"));
if ($tmp[0] == 0 || empty($tmp[0])) {
    mysqli_query($dbTmp, "INSERT INTO `" . $_SESSION['tbl_prefix'] . "misc` (`type`, `intitule`, `valeur`) VALUES ('admin', 'syslog_enable', '0')");
    mysqli_query($dbTmp, "INSERT INTO `" . $_SESSION['tbl_prefix'] . "misc` (`type`, `intitule`, `valeur`) VALUES ('admin', 'syslog_host', 'localhost')");