Changeset 6202

Show
Ignore:
Timestamp:
08/20/08 13:44:57 (5 months ago)
Author:
jmathis
Message:

Apply standard

Location:
trunk/centreon/www/include/configuration/configObject
Files:
20 modified

Legend:

Unmodified
Added
Removed
  • trunk/centreon/www/include/configuration/configObject/command/DB-Func.php

    r5226 r6202  
    1616 */ 
    1717  
    18  
    1918        if (!isset ($oreon)) 
    2019                exit (); 
     
    2322                global $pearDB, $form; 
    2423                $id = NULL; 
     24                 
    2525                if (isset($form)) 
    2626                        $id = $form->getSubmitValue('command_id'); 
    27                 $DBRESULT =& $pearDB->query("SELECT command_name, command_id FROM command WHERE command_name = '".htmlentities($name, ENT_QUOTES)."'"); 
     27                 
     28                $DBRESULT =& $pearDB->query("SELECT `command_name`, `command_id` FROM `command` WHERE `command_name` = '".htmlentities($name, ENT_QUOTES)."'"); 
    2829                if (PEAR::isError($DBRESULT)) 
    2930                        print "DB Error : ".$DBRESULT->getDebugInfo()."<br />"; 
    3031                $command =& $DBRESULT->fetchRow(); 
    31                 #Modif case 
    32                 if ($DBRESULT->numRows() >= 1 && $command["command_id"] == $id)  
     32                if ($DBRESULT->numRows() >= 1 && $command["command_id"] == $id) { 
     33                        /* 
     34                         * Mofication case 
     35                         */ 
    3336                        return true; 
    34                 #Duplicate entry 
    35                 else if ($DBRESULT->numRows() >= 1 && $command["command_id"] != $id) 
     37                } else if ($DBRESULT->numRows() >= 1 && $command["command_id"] != $id) { 
     38                        /* 
     39                         * Duplicate case 
     40                         */ 
    3641                        return false; 
    37                 else 
     42                } else 
    3843                        return true; 
    3944        } 
     
    4146        function deleteCommandInDB ($commands = array())        { 
    4247                global $pearDB; 
    43                 foreach($commands as $key=>$value)      { 
    44                         $DBRESULT =& $pearDB->query("DELETE FROM command WHERE command_id = '".$key."'"); 
     48                 
     49                foreach ($commands as $key => $value)   { 
     50                        $DBRESULT =& $pearDB->query("DELETE FROM `command` WHERE `command_id` = '".$key."'"); 
    4551                        if (PEAR::isError($DBRESULT)) 
    4652                                print "DB Error : ".$DBRESULT->getDebugInfo()."<br />"; 
     
    4955         
    5056        function multipleCommandInDB ($commands = array(), $nbrDup = array())   { 
    51                 foreach($commands as $key=>$value)      { 
    52                         global $pearDB; 
    53                         $DBRESULT =& $pearDB->query("SELECT * FROM command WHERE command_id = '".$key."' LIMIT 1"); 
     57                global $pearDB; 
     58                         
     59                foreach($commands as $key => $value)    { 
     60                         
     61                        $DBRESULT =& $pearDB->query("SELECT * FROM `command` WHERE `command_id` = '".$key."' LIMIT 1"); 
    5462                        if (PEAR::isError($DBRESULT)) 
    5563                                print "DB Error : ".$DBRESULT->getDebugInfo()."<br />"; 
     64 
    5665                        $row = $DBRESULT->fetchRow(); 
    5766                        $row["command_id"] = ''; 
     67 
    5868                        for ($i = 1; $i <= $nbrDup[$key]; $i++) { 
    5969                                $val = null; 
     70 
    6071                                foreach ($row as $key2=>$value2)        { 
    61                                         $key2 == "command_name" ? ($command_name = $value2 = $value2."_".$i) : null; 
     72                                        $key2 == "`command_name`" ? ($command_name = $value2 = $value2."_".$i) : null; 
    6273                                        $val ? $val .= ($value2 != NULL?(", '".$value2."'"):", NULL") : $val .= ($value2 != NULL?("'".$value2."'"):"NULL"); 
    6374                                } 
     75 
    6476                                if (testCmdExistence($command_name))    { 
    65                                         $val ? $rq = "INSERT INTO command VALUES (".$val.")" : $rq = null; 
     77                                        $val ? $rq = "INSERT INTO `command` VALUES (".$val.")" : $rq = null; 
    6678                                        $DBRESULT =& $pearDB->query($rq); 
    6779                                        if (PEAR::isError($DBRESULT)) 
     
    7890         
    7991        function updateCommand($cmd_id = null)  { 
    80                 if (!$cmd_id) return; 
    81                 global $form; 
    82                 global $pearDB; 
     92                global $form, $pearDB; 
     93                 
     94                if (!$cmd_id)  
     95                        return; 
     96                 
    8397                $ret = array(); 
    8498                $ret = $form->getSubmitValues(); 
     99                 
    85100                set_magic_quotes_runtime(1); 
     101                 
    86102                $ret["command_line"] = str_replace('\n', "#BR#", $ret["command_line"]); 
    87103                $ret["command_line"] = str_replace('\t', "#T#", $ret["command_line"]); 
     
    89105                $ret["command_line"] = str_replace('/', "#S#", $ret["command_line"]); 
    90106                $ret["command_line"] = str_replace('\\', "#BS#", $ret["command_line"]); 
    91                 $ret["command_example"] = str_replace("\n", "#BR#", $ret["command_example"]); 
    92                 $ret["command_example"] = str_replace("\t", "#T#", $ret["command_example"]); 
    93                 $ret["command_example"] = str_replace("\r", "#R#", $ret["command_example"]); 
     107                 
     108                $ret["command_example"] = str_replace('\n', "#BR#", $ret["command_example"]); 
     109                $ret["command_example"] = str_replace('\t', "#T#", $ret["command_example"]); 
     110                $ret["command_example"] = str_replace('\r', "#R#", $ret["command_example"]); 
    94111                $ret["command_example"] = str_replace('/', "#S#", $ret["command_example"]); 
    95112                $ret["command_example"] = str_replace('\\', "#BS#", $ret["command_example"]); 
    96                 $rq = "UPDATE command "; 
    97                 $rq .= "SET command_name = '".htmlentities($ret["command_name"], ENT_QUOTES)."', " . 
    98                                 "command_line = '".htmlentities($ret["command_line"], ENT_QUOTES)."', " . 
    99                                 "command_example = '".htmlentities($ret["command_example"], ENT_QUOTES)."', " . 
    100                                 "command_type = '".htmlentities($ret["command_type"]["command_type"], ENT_QUOTES)."', " . 
    101                                 "graph_id = '".htmlentities($ret["graph_id"], ENT_QUOTES)."' " . 
    102                                 "WHERE command_id = '".$cmd_id."'"; 
     113                 
     114                $rq = "UPDATE `command` SET `command_name` = '".htmlentities($ret["command_name"], ENT_QUOTES)."', " . 
     115                                "`command_line` = '".htmlentities($ret["command_line"], ENT_QUOTES)."', " . 
     116                                "`command_example` = '".htmlentities($ret["command_example"], ENT_QUOTES)."', " . 
     117                                "`command_type` = '".htmlentities($ret["command_type"]["command_type"], ENT_QUOTES)."', " . 
     118                                "`graph_id` = '".htmlentities($ret["graph_id"], ENT_QUOTES)."' " . 
     119                                "WHERE `command_id` = '".$cmd_id."'"; 
    103120                $DBRESULT =& $pearDB->query($rq); 
    104121                if (PEAR::isError($DBRESULT)) 
     
    112129         
    113130        function insertCommand($ret = array())  { 
    114                 global $form; 
    115                 global $pearDB; 
     131                global $form, $pearDB; 
    116132                if (!count($ret)) 
    117133                        $ret = $form->getSubmitValues(); 
    118134                set_magic_quotes_runtime(1); 
     135                 
    119136                $ret["command_line"] = str_replace("\n", "#BR#", $ret["command_line"]); 
    120137                $ret["command_line"] = str_replace("\t", "#T#", $ret["command_line"]); 
     
    122139                $ret["command_line"] = str_replace('/', "#S#", $ret["command_line"]); 
    123140                $ret["command_line"] = str_replace('\\', "#BS#", $ret["command_line"]); 
     141                 
    124142                $ret["command_example"] = str_replace("\n", "#BR#", $ret["command_example"]); 
    125143                $ret["command_example"] = str_replace("\t", "#T#", $ret["command_example"]); 
     
    127145                $ret["command_example"] = str_replace('/', "#S#", $ret["command_example"]); 
    128146                $ret["command_example"] = str_replace('\\', "#BS#", $ret["command_example"]); 
    129                 $rq = "INSERT INTO command "; 
    130                 $rq .= "(command_name, command_line, command_example, command_type, graph_id) "; 
    131                 $rq .= "VALUES "; 
    132                 $rq .= "('".htmlentities($ret["command_name"], ENT_QUOTES)."', '".htmlentities($ret["command_line"], ENT_QUOTES)."', '".htmlentities($ret["command_example"], ENT_QUOTES)."', '".$ret["command_type"]["command_type"]."', '".$ret["graph_id"]."')"; 
     147                 
     148                /* 
     149                 * Insert 
     150                 */ 
     151                $rq = "INSERT INTO `command` (`command_name`, `command_line`, `command_example`, `command_type`, `graph_id`) "; 
     152                $rq .= "VALUES ('".htmlentities($ret["command_name"], ENT_QUOTES)."', '".htmlentities($ret["command_line"], ENT_QUOTES)."', '".htmlentities($ret["command_example"], ENT_QUOTES)."', '".$ret["command_type"]["command_type"]."', '".$ret["graph_id"]."')"; 
    133153                $DBRESULT =& $pearDB->query($rq); 
    134154                if (PEAR::isError($DBRESULT)) 
    135155                        print "DB Error : ".$DBRESULT->getDebugInfo()."<br />"; 
    136                 $DBRESULT =& $pearDB->query("SELECT MAX(command_id) FROM command"); 
     156                 
     157                /* 
     158                 * Get Max ID 
     159                 */ 
     160                $DBRESULT =& $pearDB->query("SELECT MAX(command_id) FROM `command`"); 
    137161                if (PEAR::isError($DBRESULT)) 
    138162                        print "DB Error : ".$DBRESULT->getDebugInfo()."<br />"; 
    139163                $cmd_id = $DBRESULT->fetchRow(); 
     164                 
    140165                return ($cmd_id["MAX(command_id)"]); 
    141166        } 
     
    144169                global $oreon; 
    145170                $plugins = array(); 
    146                 $is_not_a_plugin = array("."=>".", ".."=>"..", "oreon.conf"=>"oreon.conf", "oreon.pm"=>"oreon.pm", "utils.pm"=>"utils.pm", "negate"=>"negate"); 
     171                $is_not_a_plugin = array("." => 1, ".." => 1, "oreon.conf" => 1, "oreon.pm" => 1, "utils.pm" => 1, "negate" => 1, "centreon.conf" => 1, "centreon.pm" => 1); 
    147172                $handle[$rep] = opendir($rep); 
    148173                while (false !== ($filename = readdir($handle[$rep]))){ 
     
    152177                                        $plugins = array_merge($plugins, $plg_tmp); 
    153178                                        unset($plg_tmp); 
    154                                 } else if (!array_key_exists($filename, $is_not_a_plugin) && substr($filename, -1)!= "~"){ 
     179                                } else if (!isset($is_not_a_plugin[$filename]) && substr($filename, -1)!= "~"){ 
    155180                                        $key = substr($rep."/".$filename, strlen($oreon->optGen["nagios_path_plugins"])); 
    156181                                        $plugins[$key] = $key; 
  • trunk/centreon/www/include/configuration/configObject/command/command.php

    r6145 r6202  
    6464        } 
    6565 
    66         if ($min) 
     66        if ($min) { 
    6767                switch ($o)     { 
    68                         case "h"        : require_once($path."minHelpCommand.php"); break; #Show Help Command   # Wistof 
    69                         case "p"        : require_once($path."minPlayCommand.php"); break; #Test the plugin 
    70                         default         : require_once($path."minCommand.php"); break; 
     68                        case "h"        : 
     69                                /* 
     70                                 * Show Help Command 
     71                                 */  
     72                                require_once($path."minHelpCommand.php");  
     73                                break;  
     74                        case "p"        :  
     75                                /* 
     76                                 * Test the plugin 
     77                                 */ 
     78                                require_once($path."minPlayCommand.php");  
     79                                break;  
     80                        default         :  
     81                                require_once($path."minCommand.php");  
     82                                break; 
    7183                } 
    72         else 
     84        } else { 
    7385                switch ($o)     { 
    74                         case "a"        : require_once($path."formCommand.php"); break; #Add a Command 
    75                         case "w"        : require_once($path."formCommand.php"); break; #Watch a Command 
    76                         case "c"        : require_once($path."formCommand.php"); break; #Modify a Command 
    77                         case "m"        : multipleCommandInDB(isset($select) ? $select : array(), $dupNbr); require_once($path."listCommand.php"); break; #Duplicate n Commands 
    78                         case "d"        : deleteCommandInDB(isset($select) ? $select : array()); require_once($path."listCommand.php"); break; #Delete n Commands 
    79                         default         : require_once($path."listCommand.php"); break; 
     86                        case "a"        :  
     87                                /* 
     88                                 * Add a Command 
     89                                 */ 
     90                                require_once($path."formCommand.php");  
     91                                break; 
     92                        case "w"        :  
     93                                /* 
     94                                 * Watch a Command 
     95                                 */ 
     96                                require_once($path."formCommand.php");  
     97                                break; 
     98                        case "c"        : 
     99                                /* 
     100                                 * Modify a Command 
     101                                 */  
     102                                require_once($path."formCommand.php");  
     103                                break;  
     104                        case "m"        : 
     105                                /* 
     106                                 * Duplicate n Commands 
     107                                 */  
     108                                multipleCommandInDB(isset($select) ? $select : array(), $dupNbr);  
     109                                require_once($path."listCommand.php");  
     110                                break;  
     111                        case "d"        : 
     112                                /* 
     113                                 * Delete n Commands 
     114                                 */  
     115                                deleteCommandInDB(isset($select) ? $select : array());  
     116                                require_once($path."listCommand.php");  
     117                                break; 
     118                        default         :  
     119                                require_once($path."listCommand.php");  
     120                                break; 
    80121                } 
     122        } 
    81123?> 
  • trunk/centreon/www/include/configuration/configObject/command/formCommand.ihtml

    r5379 r6202  
    11{$form.javascript} 
    2 {$insertValueQuery} 
     2<script type='text/javascript'> 
     3        <!-- 
     4        function insertValueQuery(elem) { 
     5            var myQuery = document.Form.command_line; 
     6                if(elem == 1)   { 
     7                        var myListBox = document.Form.resource; 
     8                } else if (elem == 2)   { 
     9                        var myListBox = document.Form.plugins; 
     10                } else if (elem == 3)   { 
     11                        var myListBox = document.Form.macros; 
     12                } 
     13            if (myListBox.options.length > 0) { 
     14                var chaineAj = ''; 
     15                var NbSelect = 0; 
     16                for(var i=0; i<myListBox.options.length; i++) { 
     17                    if (myListBox.options[i].selected){ 
     18                        NbSelect++; 
     19                        if (NbSelect > 1) 
     20                            chaineAj += ', '; 
     21                        chaineAj += myListBox.options[i].value; 
     22                    } 
     23                } 
     24         
     25                if (document.selection) { 
     26                        // IE support 
     27                    myQuery.focus(); 
     28                    sel = document.selection.createRange(); 
     29                    sel.text = chaineAj; 
     30                    document.Form.insert.focus(); 
     31                } else if (document.Form.command_line.selectionStart || document.Form.command_line.selectionStart == '0') { 
     32                        // MOZILLA/NETSCAPE support 
     33                    var startPos = document.Form.command_line.selectionStart; 
     34                    var endPos = document.Form.command_line.selectionEnd; 
     35                    var chaineSql = document.Form.command_line.value; 
     36                    myQuery.value = chaineSql.substring(0, startPos) + chaineAj + chaineSql.substring(endPos, chaineSql.length); 
     37                } else { 
     38                    myQuery.value += chaineAj; 
     39                } 
     40            } 
     41        } 
     42        //--> 
     43</script> 
    344<form {$form.attributes}> 
    445        <div id="validFormTop"> 
  • trunk/centreon/www/include/configuration/configObject/command/formCommand.php

    r6061 r6202  
    1616 */ 
    1717  
    18         # 
    19         ## Database retrieve information for Command 
    20         #        
    21         function myDecodeCommand($arg)  { 
     18        /* 
     19         * Form Rules 
     20         */ 
     21         
     22        function myReplace()    { 
     23                global $form; 
     24                $ret = $form->getSubmitValues(); 
     25                return (str_replace(" ", "_", $ret["command_name"])); 
     26        } 
     27         
     28        /* 
     29         * Database retrieve information for Command 
     30         */ 
     31        function myDecodeCommand($arg) { 
    2232                $arg = html_entity_decode($arg, ENT_QUOTES); 
    2333                $arg = str_replace('#BR#', "\\n", $arg); 
     
    3242        $cmd = array(); 
    3343        if (($o == "c" || $o == "w") && $command_id)    {                
    34                 $DBRESULT =& $pearDB->query("SELECT * FROM command WHERE command_id = '".$command_id."' LIMIT 1"); 
     44                $DBRESULT =& $pearDB->query("SELECT * FROM `command` WHERE `command_id` = '".$command_id."' LIMIT 1"); 
    3545                if (PEAR::isError($DBRESULT)) 
    3646                        print "DB Error : ".$DBRESULT->getDebugInfo()."<br />"; 
     
    3848                $cmd = array_map("myDecodeCommand", $DBRESULT->fetchRow()); 
    3949        } 
    40         # 
    41         ## Database retrieve information for differents elements list we need on the page 
    42         # 
    43         # Resource Macro 
     50         
     51        /* 
     52         * Resource Macro 
     53         */ 
     54 
    4455        $resource = array(); 
    45         $DBRESULT =& $pearDB->query("SELECT DISTINCT resource_name, resource_comment FROM cfg_resource ORDER BY resource_line"); 
     56        $DBRESULT =& $pearDB->query("SELECT DISTINCT `resource_name`, `resource_comment` FROM `cfg_resource` ORDER BY `resource_line`"); 
    4657        if (PEAR::isError($DBRESULT)) 
    4758                print "DB Error : ".$DBRESULT->getDebugInfo()."<br />"; 
     
    5768         */ 
    5869        $graphTpls = array(NULL=>NULL); 
    59         $DBRESULT =& $pearDB->query("SELECT graph_id, name FROM giv_graphs_template ORDER BY name"); 
     70        $DBRESULT =& $pearDB->query("SELECT `graph_id`, `name` FROM `giv_graphs_template` ORDER BY `name`"); 
    6071        if (PEAR::isError($DBRESULT)) 
    6172                print "DB Error : ".$DBRESULT->getDebugInfo()."<br />"; 
    62         while($graphTpl =& $DBRESULT->fetchRow()) 
     73        while ($graphTpl =& $DBRESULT->fetchRow()) 
    6374                $graphTpls[$graphTpl["graph_id"]] = $graphTpl["name"]; 
    6475        $DBRESULT->free(); 
    6576         
    66         # Nagios Macro 
     77        /* 
     78         * Nagios Macro 
     79         */ 
    6780        $macros = array(); 
    68         $DBRESULT =& $pearDB->query("SELECT macro_name FROM nagios_macro ORDER BY macro_name"); 
     81        $DBRESULT =& $pearDB->query("SELECT `macro_name` FROM `nagios_macro` ORDER BY `macro_name`"); 
    6982        if (PEAR::isError($DBRESULT)) 
    7083                print "DB Error : ".$DBRESULT->getDebugInfo()."<br />"; 
    71         while($row =& $DBRESULT->fetchRow()) 
     84        while ($row =& $DBRESULT->fetchRow()) 
    7285                $macros[$row["macro_name"]] = $row["macro_name"]; 
    7386        $DBRESULT->free(); 
    74         # 
    75         # End of "database-retrieved" information 
    76         ########################################################## 
    77         ########################################################## 
    78         # Var information to format the element 
    79         # 
     87         
    8088        $attrsText              = array("size"=>"35"); 
    8189        $attrsTextarea  = array("rows"=>"9", "cols"=>"65"); 
    8290 
    83         # 
    84         ## Form begin 
    85         # 
     91        /* 
     92         * Form begin 
     93         */ 
    8694        $form = new HTML_QuickForm('Form', 'post', "?p=".$p); 
    8795        if ($o == "a") 
     
    92100                $form->addElement('header', 'title', _("View a Command")); 
    93101 
    94         # 
    95         ## Command information 
    96         # 
     102        /* 
     103         * Command information 
     104         */ 
    97105        if ($type == "1") 
    98106                $form->addElement('header', 'information', _("Notification")); 
     
    103111        else 
    104112                $form->addElement('header', 'information', _("Information")); 
     113         
    105114        $cmdType[] = &HTML_QuickForm::createElement('radio', 'command_type', null, _("Notification"), '1'); 
    106115        $cmdType[] = &HTML_QuickForm::createElement('radio', 'command_type', null, _("Check"), '2'); 
    107116        $cmdType[] = &HTML_QuickForm::createElement('radio', 'command_type', null, _("Misc"), '3'); 
     117         
    108118        $form->addGroup($cmdType, 'command_type', _("Command Type"), '&nbsp;&nbsp;'); 
    109119        $form->setDefaults(array('command_type' => '2')); 
     
    126136        $form->addElement('select', 'plugins', null, $plugins_list); 
    127137         
    128         # 
    129         ## Further informations 
    130         # 
     138        /* 
     139         * Further informations 
     140         */ 
    131141        $form->addElement('hidden', 'command_id'); 
    132142        $redirectType = $form->addElement('hidden', 'type'); 
     
    134144        $redirect =& $form->addElement('hidden', 'o'); 
    135145        $redirect->setValue($o); 
    136  
    137         # 
    138         ## Form Rules 
    139         # 
    140         function myReplace()    { 
    141                 global $form; 
    142                 $ret = $form->getSubmitValues(); 
    143                 return (str_replace(" ", "_", $ret["command_name"])); 
    144         } 
     146         
    145147        $form->applyFilter('__ALL__', 'myTrim'); 
    146148        $form->applyFilter('command_name', 'myReplace'); 
     
    152154        $form->setRequiredNote("<font style='color: red;'>*</font>". _(" Required fields")); 
    153155 
    154         # 
    155         ##End of form definition 
    156         # 
    157  
    158         # Smarty template Init 
     156        /* 
     157         * Smarty template Init 
     158         */ 
    159159        $tpl = new Smarty(); 
    160160        $tpl = initSmartyTpl($path, $tpl); 
    161161 
    162         # Just watch a Command information 
     162        /* 
     163         * Just watch a Command information 
     164         */ 
    163165        if ($o == "w")  { 
    164166                $form->addElement("button", "change", _("Modify"), array("onClick"=>"javascript:window.location.href='?p=".$p."&o=c&command_id=".$command_id."&type=".$type."'")); 
    165167            $form->setDefaults($cmd); 
    166168                $form->freeze(); 
    167         } 
    168         # Modify a Command information 
    169         else if ($o == "c")     { 
     169        } else if ($o == "c")   { 
     170                /* 
     171                 * Modify a Command information 
     172                 */ 
    170173                $subC =& $form->addElement('submit', 'submitC', _("Save")); 
    171174                $res =& $form->addElement('reset', 'reset', _("Reset")); 
    172