glpi_flush() static public method

Flush the current displayed items (do not works really fine)
static public glpi_flush ( )
コード例 #1
0
ファイル: html.class.php プロジェクト: OlivierLM/glpi
 /**
  * Manage progresse bars
  *
  * @since version 0.85
  *
  * @param $id                 HTML ID of the progress bar
  * @param $options    array   progress status
  *                    - create    do we have to create it ?
  *                    - message   add or change the message
  *                    - percent   current level
  *
  *
  * @return nothing (display)
  **/
 static function progressBar($id, array $options = array())
 {
     $params = array();
     $params['create'] = false;
     $params['message'] = NULL;
     $params['percent'] = -1;
     if (is_array($options) && count($options)) {
         foreach ($options as $key => $val) {
             $params[$key] = $val;
         }
     }
     if ($params['create']) {
         echo "<div class='doaction_cadre'>";
         echo "<div class='doaction_progress' id='{$id}'>";
         echo "<div class='doaction_progress_text' id='" . $id . "_text' >&nbsp;</div>";
         echo "</div>";
         echo "</div><br>";
         echo Html::scriptBlock(self::jsGetElementbyID($id) . ".progressbar();");
     }
     if ($params['message'] !== NULL) {
         echo Html::scriptBlock(self::jsGetElementbyID($id . '_text') . ".text(\"" . addslashes($params['message']) . "\");");
     }
     if ($params['percent'] >= 0 && $params['percent'] <= 100) {
         echo Html::scriptBlock(self::jsGetElementbyID($id) . ".progressbar('option', 'value', " . $params['percent'] . " );");
     }
     if (!$params['create']) {
         Html::glpi_flush();
     }
 }
コード例 #2
0
function plugin_fusioninventory_displayMigrationMessage($id, $msg = "")
{
    static $created = 0;
    static $deb;
    if ($created != $id) {
        if (empty($msg)) {
            $msg = __('Work in progress...');
        }
        echo "<div id='migration_message_{$id}'><p class='center'>{$msg}</p></div>";
        $created = $id;
        $deb = time();
    } else {
        if (empty($msg)) {
            $msg = __('Task completed.');
        }
        $fin = time();
        $tps = Html::timestampToString($fin - $deb);
        echo "<script type='text/javascript'>document.getElementById('migration_message_{$id}')." . "innerHTML = '<p class=\"center\">{$msg} ({$tps})</p>';</script>\n";
    }
    Html::glpi_flush();
}
コード例 #3
0
ファイル: migration.class.php プロジェクト: pvasener/glpi
 /**
  * Additional message in global message
  *
  * @param $msg    text  to display
  **/
 function displayMessage($msg)
 {
     $now = time();
     $tps = Html::timestampToString($now - $this->deb);
     echo "<script type='text/javascript'>document.getElementById('" . $this->current_message_area_id . "').innerHTML=\"<p class='center'>" . addslashes($msg) . " ({$tps})</p>\";" . "</script>\n";
     $this->flushLogDisplayMessage();
     $this->lastMessage = array('time' => time(), 'msg' => $msg);
     Html::glpi_flush();
 }
コード例 #4
0
ファイル: backup.php プロジェクト: stweil/glpi
/**  Restore a mysql dump
 *
 * @param $DB        DB object
 * @param $dumpFile  dump file
 * @param $duree     max delay before refresh
**/
function restoreMySqlDump($DB, $dumpFile, $duree)
{
    global $DB, $TPSCOUR, $offset, $cpt;
    // $dumpFile, fichier source
    // $duree=timeout pour changement de page (-1 = aucun)
    // Desactivation pour empecher les addslashes au niveau de la creation des tables
    // En plus, au niveau du dump on considere qu'on est bon
    // set_magic_quotes_runtime(0);
    if (!file_exists($dumpFile)) {
        echo sprintf(__('File %s not found.'), $dumpFile) . "<br>";
        return false;
    }
    if (substr($dumpFile, -2) == "gz") {
        $fileHandle = gzopen($dumpFile, "rb");
    } else {
        $fileHandle = fopen($dumpFile, "rb");
    }
    if (!$fileHandle) {
        //TRASN: %s is the name of the file
        echo sprintf(__('Unauthorized access to the file %s'), $dumpFile) . "<br>";
        return false;
    }
    if ($offset != 0) {
        if (substr($dumpFile, -2) == "gz") {
            if (gzseek($fileHandle, $offset, SEEK_SET) != 0) {
                //erreur
                //TRANS: %s is the number of the byte
                printf(__("Unable to find the byte %s"), Html::formatNumber($offset, false, 0));
                echo "<br>";
                return false;
            }
        } else {
            if (fseek($fileHandle, $offset, SEEK_SET) != 0) {
                //erreur
                //TRANS: %s is the number of the byte
                printf(__("Unable to find the byte %s"), Html::formatNumber($offset, false, 0));
                echo "<br>";
                return false;
            }
        }
        Html::glpi_flush();
    }
    $formattedQuery = "";
    if (substr($dumpFile, -2) == "gz") {
        while (!gzeof($fileHandle)) {
            current_time();
            if ($duree > 0 && $TPSCOUR >= $duree) {
                //on atteint la fin du temps imparti
                return true;
            }
            // specify read length to be able to read long lines
            $buffer = gzgets($fileHandle, 102400);
            // do not strip comments due to problems when # in begin of a data line
            $formattedQuery .= $buffer;
            if (substr(rtrim($formattedQuery), -1) == ";") {
                // Do not use the $DB->query
                if ($DB->query($formattedQuery)) {
                    //if no success continue to concatenate
                    $offset = gztell($fileHandle);
                    $formattedQuery = "";
                    $cpt++;
                }
            }
        }
    } else {
        while (!feof($fileHandle)) {
            current_time();
            if ($duree > 0 && $TPSCOUR >= $duree) {
                //on atteint la fin du temps imparti
                return true;
            }
            // specify read length to be able to read long lines
            $buffer = fgets($fileHandle, 102400);
            // do not strip comments due to problems when # in begin of a data line
            $formattedQuery .= $buffer;
            if (substr(rtrim($formattedQuery), -1) == ";") {
                // Do not use the $DB->query
                if ($DB->query($formattedQuery)) {
                    //if no success continue to concatenate
                    $offset = ftell($fileHandle);
                    $formattedQuery = "";
                    $cpt++;
                }
            }
        }
    }
    if ($DB->error) {
        echo "<hr>";
        //TRANS: %s is the SQL query which generates the error
        printf(__("SQL error starting from %s"), "[{$formattedQuery}]");
        echo "<br>" . $DB->error() . "<hr>";
    }
    if (substr($dumpFile, -2) == "gz") {
        gzclose($fileHandle);
    } else {
        fclose($fileHandle);
    }
    $offset = -1;
    return true;
}
コード例 #5
0
ファイル: update_content.php プロジェクト: jose-martins/glpi
    $query = "SELECT `utf8_conv`\n             FROM `{$config_table}`\n             WHERE `id` = '1'";
    $result = $DB->query($query);
    $data = $DB->fetch_assoc($result);
    if ($data["utf8_conv"]) {
        $complete_utf8 = false;
    }
}
if ($offsettable >= 0 && $complete_utf8) {
    if ($percent >= 0) {
        Html::displayProgressBar(400, $percent);
        echo "</div></div></body></html>";
        Html::glpi_flush();
    }
    if (UpdateContent($DB, $duree, $rowlimit, $conv_utf8, $complete_utf8)) {
        echo "<br><a href='update_content.php?dump=1&amp;duree={$duree}&amp;rowlimit=" . "{$rowlimit}&amp;offsetrow={$offsetrow}&amp;offsettable={$offsettable}&amp;cpt={$cpt}'>" . __('Automatic redirection, else click') . "</a>";
        echo "<script language='javascript' type='text/javascript'>\n             window.location=\"update_content.php?dump=1&duree={$duree}&rowlimit={$rowlimit}&offsetrow=" . "{$offsetrow}&offsettable={$offsettable}&cpt={$cpt}\";</script>";
        Html::glpi_flush();
        exit;
    }
} else {
    echo "<p><a class='vsubmit' href='../index.php'>" . __('Use GLPI') . "</a></p>";
    echo "</div></div></body></html>";
}
if ($conv_utf8) {
    $query = "ALTER TABLE `{$config_table}`\n             ADD `utf8_conv` INT( 11 ) DEFAULT '0' NOT NULL";
    $DB->queryOrDie($query, " 0.6 add utf8_conv to {$config_table}");
}
if ($complete_utf8) {
    $DB->query("ALTER DATABASE `" . $DB->dbdefault . "` DEFAULT\n               CHARACTER SET utf8 COLLATE utf8_unicode_ci");
    $DB->query("UPDATE `{$config_table}`\n               SET `utf8_conv` = '1'\n               WHERE `id` = '1'");
}
コード例 #6
0
/**
 * Upgrade => 1.16
 * 
 * Upgrade fields to be compatable with mysql strict mode
 */
function plugin_customfields_upgradeto116()
{
    global $DB;
    // Upgrade
    $query = "DROP TABLE IF EXISTS `glpi_plugin_customfields`";
    $DB->query($query) or die($DB->error());
    $query = "CREATE TABLE `glpi_plugin_customfields` (\n               `ID` int(11) NOT NULL auto_increment,\n               `device_type` int(11) NOT NULL default '0',\n               `enabled` smallint(6) NOT NULL default '0',\n               PRIMARY KEY (`ID`)\n             ) ENGINE=MyISAM\n             DEFAULT\n              CHARSET=utf8\n              COLLATE=utf8_unicode_ci\n              AUTO_INCREMENT=3";
    $DB->query($query) or die($DB->error());
    $query = "INSERT INTO `glpi_plugin_customfields`\n                    (`device_type`,`enabled`)\n             VALUES ('-1', '116')";
    $DB->query($query) or die($DB->error());
    $query = "INSERT INTO `glpi_plugin_customfields`\n                    (`device_type`)\n             VALUES ('1'), ('41'), ('4'), ('6'), ('39'), ('20'), ('2'),\n             ('42'), ('5'), ('3'), ('11'),\n                    ('17'), ('23'), ('16'), ('7'), ('8'), ('10'), ('13'),\n                    ('15'), ('27'), ('28')";
    $DB->query($query) or die($DB->error());
    $transform = array();
    $transform['general'] = 'VARCHAR(255) collate utf8_unicode_ci default NULL';
    $transform['dropdown'] = 'INT(11) NOT NULL default \'0\'';
    $transform['yesno'] = 'SMALLINT(6) NOT NULL default \'0\'';
    $transform['text'] = 'TEXT collate utf8_unicode_ci';
    $transform['notes'] = 'LONGTEXT collate utf8_unicode_ci';
    $transform['number'] = 'INT(11) NOT NULL default \'0\'';
    $transform['money'] = 'DECIMAL(20,4) NOT NULL default \'0.0000\'';
    $sql = "SELECT `itemtype`, `system_name`, `data_type`\n           FROM `glpi_plugin_customfields_fields`\n           WHERE `deleted` = 0\n                 AND `data_type` != 'sectionhead'\n                 AND `data_type` != 'date'\n           ORDER BY `itemtype`, `sort_order`, `ID`";
    $result = $DB->query($sql) or die($DB->error());
    set_time_limit(300);
    echo 'Updating Custom Fields...';
    while ($data = $DB->fetch_array($result)) {
        echo '.';
        Html::glpi_flush();
        $table = plugin_customfields_table($data['itemtype']);
        $field = $data['system_name'];
        $newtype = $transform[$data['data_type']];
        $sql = "ALTER TABLE `{$table}`\n              CHANGE `{$field}` `{$field}` {$newtype}";
        $DB->query($query) or die($DB->error());
        if (in_array($data['data_type'], array('general', 'text', 'notes'))) {
            $sql = "UPDATE `{$table}`\n                 SET `{$field}` = NULL\n                 WHERE `{$field}` = ''";
            $DB->query($sql) or die($DB->error());
        }
    }
    $query = "ALTER TABLE `glpi_plugin_customfields_fields`\n             CHANGE `system_name` `system_name` varchar(40)\n              collate utf8_unicode_ci default NULL,\n             CHANGE `label` `label` varchar(70)\n              collate utf8_unicode_ci default NULL,\n             CHANGE `default_value` `default_value` varchar(255)\n              collate utf8_unicode_ci default NULL,\n             CHANGE `dropdown_table` `dropdown_table` varchar(255)\n              collate utf8_unicode_ci default NULL";
    $DB->query($query) or die($DB->error());
    $query = "ALTER TABLE `glpi_plugin_customfields_dropdowns`\n             CHANGE `system_name` `system_name` varchar(40)\n              collate utf8_unicode_ci default NULL,\n             CHANGE `name` `name` varchar(70)\n              collate utf8_unicode_ci default NULL,\n             CHANGE `dropdown_table` `dropdown_table` varchar(255)\n              collate utf8_unicode_ci default NULL";
    $DB->query($query) or die($DB->error());
    $query = "UPDATE `glpi_plugin_customfields_fields`\n             SET `default_value` = NULL\n             WHERE `default_value` = ''";
    $DB->query($query) or die($DB->error());
    echo 'finished.';
    Html::glpi_flush();
}
コード例 #7
0
 function displayReport(&$result, $PluginAddressingAddressing)
 {
     global $DB, $CFG_GLPI;
     $network = $PluginAddressingAddressing->fields["networks_id"];
     $ping = $PluginAddressingAddressing->fields["use_ping"];
     $PluginAddressingConfig = new PluginAddressingConfig();
     $PluginAddressingConfig->getFromDB('1');
     $system = $PluginAddressingConfig->fields["used_system"];
     // Set display type for export if define
     $output_type = Search::HTML_OUTPUT;
     if (isset($_GET["display_type"])) {
         $output_type = $_GET["display_type"];
     }
     $header_num = 1;
     $nbcols = 6;
     $ping_response = 0;
     $parameters = "id=";
     $row_num = 1;
     echo Search::showHeader($output_type, 1, $nbcols, 1);
     echo $this->displaySearchNewLine($output_type);
     echo Search::showHeaderItem($output_type, __('IP'), $header_num);
     echo Search::showHeaderItem($output_type, __('Connected to'), $header_num);
     echo Search::showHeaderItem($output_type, _n('User', 'Users', 1), $header_num);
     echo Search::showHeaderItem($output_type, __('MAC address'), $header_num);
     echo Search::showHeaderItem($output_type, __('Item type'), $header_num);
     echo Search::showHeaderItem($output_type, __('Free Ip', 'addressing'), $header_num);
     // End Line for column headers
     echo Search::showEndLine($output_type);
     $user = new User();
     foreach ($result as $num => $lines) {
         $ip = long2ip(substr($num, 2));
         if (count($lines)) {
             if (count($lines) > 1) {
                 $disp = $PluginAddressingAddressing->fields["double_ip"];
             } else {
                 $disp = $PluginAddressingAddressing->fields["alloted_ip"];
             }
             if ($disp) {
                 foreach ($lines as $line) {
                     $row_num++;
                     $item_num = 1;
                     $name = $line["dname"];
                     $namep = $line["pname"];
                     // IP
                     echo $this->displaySearchNewLine($output_type, count($lines) > 1 ? "double" : $row_num % 2);
                     echo Search::showItem($output_type, $ip, $item_num, $row_num);
                     // Device
                     $item = new $line["itemtype"]();
                     $link = Toolbox::getItemTypeFormURL($line["itemtype"]);
                     if ($line["itemtype"] != 'NetworkEquipment') {
                         if ($item->canView()) {
                             $output_iddev = "<a href='" . $link . "?id=" . $line["on_device"] . "'>" . $name . (empty($name) || $_SESSION["glpiis_ids_visible"] ? " (" . $line["on_device"] . ")" : "") . "</a>";
                         } else {
                             $output_iddev = $name . (empty($name) || $_SESSION["glpiis_ids_visible"] ? " (" . $line["on_device"] . ")" : "");
                         }
                     } else {
                         if ($item->canView()) {
                             if (empty($namep)) {
                                 $linkp = '';
                             } else {
                                 $linkp = $namep . " - ";
                             }
                             $output_iddev = "<a href='" . $link . "?id=" . $line["on_device"] . "'>" . $linkp . $name . (empty($name) || $_SESSION["glpiis_ids_visible"] ? " (" . $line["on_device"] . ")" : "") . "</a>";
                         } else {
                             $output_iddev = $namep . " - " . $name . (empty($name) || $_SESSION["glpiis_ids_visible"] ? " (" . $line["on_device"] . ")" : "");
                         }
                     }
                     echo Search::showItem($output_type, $output_iddev, $item_num, $row_num);
                     // User
                     if ($line["users_id"] && $user->getFromDB($line["users_id"])) {
                         $username = formatUserName($user->fields["id"], $user->fields["name"], $user->fields["realname"], $user->fields["firstname"]);
                         if ($user->canView()) {
                             $output_iduser = "******" . $CFG_GLPI["root_doc"] . "/front/user.form.php?id=" . $line["users_id"] . "'>" . $username . "</a>";
                         } else {
                             $output_iduser = $username;
                         }
                         echo Search::showItem($output_type, $output_iduser, $item_num, $row_num);
                     } else {
                         echo Search::showItem($output_type, " ", $item_num, $row_num);
                     }
                     // Mac
                     if ($line["id"]) {
                         if ($item->canView()) {
                             $output_mac = "<a href='" . $CFG_GLPI["root_doc"] . "/front/networkport.form.php?id=" . $line["id"] . "'>" . $line["mac"] . "</a>";
                         } else {
                             $output_mac = $line["mac"];
                         }
                         echo Search::showItem($output_type, $output_mac, $item_num, $row_num);
                     } else {
                         echo Search::showItem($output_type, " ", $item_num, $row_num);
                     }
                     // Type
                     echo Search::showItem($output_type, $item::getTypeName(), $item_num, $row_num);
                     // Reserved
                     if ($PluginAddressingAddressing->fields["reserved_ip"] && strstr($line["pname"], "reserv")) {
                         echo Search::showItem($output_type, __('Reserved Address', 'addressing'), $item_num, $row_num);
                     } else {
                         echo Search::showItem($output_type, " ", $item_num, $row_num);
                     }
                     // End
                     echo Search::showEndLine($output_type);
                 }
             }
         } else {
             if ($PluginAddressingAddressing->fields["free_ip"]) {
                 $row_num++;
                 $item_num = 1;
                 if (!$ping) {
                     echo $this->displaySearchNewLine($output_type, "free");
                     echo Search::showItem($output_type, $ip, $item_num, $row_num);
                     echo Search::showItem($output_type, " ", $item_num, $row_num);
                 } else {
                     if ($output_type == Search::HTML_OUTPUT) {
                         Html::glpi_flush();
                     }
                     if ($this->ping($system, $ip)) {
                         $ping_response++;
                         echo $this->displaySearchNewLine($output_type, "ping_off");
                         echo Search::showItem($output_type, $ip, $item_num, $row_num);
                         echo Search::showItem($output_type, __('Ping: got a response - used Ip', 'addressing'), $item_num, $row_num);
                     } else {
                         echo $this->displaySearchNewLine($output_type, "ping_on");
                         echo Search::showItem($output_type, $ip, $item_num, $row_num);
                         echo Search::showItem($output_type, __('Ping: no response - free Ip', 'addressing'), $item_num, $row_num);
                     }
                 }
                 echo Search::showItem($output_type, " ", $item_num, $row_num);
                 echo Search::showItem($output_type, " ", $item_num, $row_num);
                 echo Search::showItem($output_type, " ", $item_num, $row_num);
                 echo Search::showItem($output_type, " ", $item_num, $row_num);
                 echo Search::showEndLine($output_type);
             }
         }
     }
     // Display footer
     echo Search::showFooter($output_type, $PluginAddressingAddressing->getTitle());
     return $ping_response;
 }