3131 die ("Sorry. You can't access directly to this file " );
3232}
3333
34- class PluginAddressingReserveip extends CommonDBTM {
34+ class PluginAddressingReserveip extends CommonDBTM
35+ {
3536 const COMPUTER = 'Computer ' ;
36- const NETWORK = 'NetworkEquipment ' ;
37- const PRINTER = 'Printer ' ;
37+ const NETWORK = 'NetworkEquipment ' ;
38+ const PRINTER = 'Printer ' ;
3839
3940 static $ rightname = 'plugin_addressing ' ;
4041
41- static function getTypeName ($ nb = 0 ) {
42+ static function getTypeName ($ nb = 0 )
43+ {
4244 return __ ("Reserve " );
4345 }
4446
45- function getPortName ($ ip ) {
46- return "reserv- " .$ ip ;
47+ function getPortName ($ ip )
48+ {
49+ return "reserv- " . $ ip ;
4750 }
4851
4952 /**
5053 * Show form
51- *
54+ *
5255 * @param type $input
5356 * @return type
5457 */
55- function reserveip ($ input = array ()) {
58+ function reserveip ($ input = array ())
59+ {
5660
5761 if (!$ this ->checkMandatoryFields ($ input )) {
5862 return false ;
5963 }
6064
6165 // Find computer
62- $ item = new $ input ['type ' ]();
66+ $ item = new $ input ['type ' ]();
6367 $ id = 0 ;
64- if (!$ item ->getFromDBByQuery ("WHERE `name`=' " . $ input ["name " ]. "' AND `entities_id`= " . $ input ['entities_id ' ]. " LIMIT 1 " )) {
68+ if (!$ item ->getFromDBByQuery ("WHERE `name`=' " . $ input ["name " ] . "' AND `entities_id`= " . $ input ['entities_id ' ] . " LIMIT 1 " )) {
6569 // Add computer
66- $ id = $ item ->add (array ("name " => $ input ["name " ],
67- "entities_id " => $ input ['entities_id ' ],
68- 'states_id ' => $ input ["states_id " ],
69- "comment " => $ input ['comment ' ]));
70+ $ id = $ item ->add (array ("name " => $ input ["name " ],
71+ "entities_id " => $ input ['entities_id ' ],
72+ 'states_id ' => $ input ["states_id " ],
73+ "comment " => $ input ['comment ' ]));
7074 } else {
7175 $ id = $ item ->getID ();
7276 //update item
73- $ item ->update (array ("id " => $ id ,
74- "entities_id " => $ input ['entities_id ' ],
75- 'states_id ' => $ input ["states_id " ],
76- "comment " => $ input ['comment ' ]));
77+ $ item ->update (array ("id " => $ id ,
78+ "entities_id " => $ input ['entities_id ' ],
79+ 'states_id ' => $ input ["states_id " ],
80+ "comment " => $ input ['comment ' ]));
7781 }
78-
82+
7983 // Add a new port
8084 if ($ id ) {
81- switch ($ input ['type ' ]){
82- case 'NetworkEquipment ' :
85+ switch ($ input ['type ' ]) {
86+ case 'NetworkEquipment ' :
8387 $ newinput = array (
84- "itemtype " => $ input ['type ' ],
85- "items_id " => $ id ,
86- "entities_id " => $ _SESSION ["glpiactive_entity " ],
87- "name " => self ::getPortName ($ input ["ip " ]),
88- "instantiation_type " => "NetworkPortAggregate " ,
89- "mac " => $ input [ " mac " ] ,
88+ "itemtype " => $ input ['type ' ],
89+ "items_id " => $ id ,
90+ "entities_id " => $ _SESSION ["glpiactive_entity " ],
91+ "name " => self ::getPortName ($ input ["ip " ]),
92+ "instantiation_type " => "NetworkPortAggregate " ,
93+ "_create_children " => 1 ,
9094 "NetworkName__ipaddresses " => array ("-100 " => $ input ["ip " ]),
95+ "mac " => $ input ["mac " ],
9196 );
9297 break ;
9398 case 'Computer ' :
9499 case 'Printer ' :
95100 $ newinput = array (
96- "itemtype " => $ input ['type ' ],
97- "items_id " => $ id ,
98- "entities_id " => $ _SESSION ["glpiactive_entity " ],
99- "name " => self ::getPortName ($ input ["ip " ]),
100- "instantiation_type " => "NetworkPortEthernet " ,
101- "mac " => $ input [ " mac " ] ,
101+ "itemtype " => $ input ['type ' ],
102+ "items_id " => $ id ,
103+ "entities_id " => $ _SESSION ["glpiactive_entity " ],
104+ "name " => self ::getPortName ($ input ["ip " ]),
105+ "instantiation_type " => "NetworkPortEthernet " ,
106+ "_create_children " => 1 ,
102107 "NetworkName__ipaddresses " => array ("-100 " => $ input ["ip " ]),
108+ "mac " => $ input ["mac " ],
103109 );
104110 break ;
105111 }
106-
112+
107113 $ np = new NetworkPort ();
108114 $ newID = $ np ->add ($ newinput );
109115
116+ Event::log ($ newID , "networkport " , 5 , "inventory " ,
117+ //TRANS: %s is the user login
118+ sprintf (__ ('%s adds an item ' ), $ _SESSION ["glpiname " ]));
110119 }
111120 }
112121
113122 /**
114123 * Check mandatory fields
115- *
124+ *
116125 * @param type $input
117126 * @return boolean
118127 */
119- function checkMandatoryFields ($ input ) {
120- $ msg = array ();
128+ function checkMandatoryFields ($ input )
129+ {
130+ $ msg = array ();
121131 $ checkKo = false ;
122132
123133 $ mandatory_fields = array ('name ' => __ ("Object's name " , 'addressing ' ),
124- 'ip ' => _n ("IP address " , "IP addresses " , 1 ));
134+ 'ip ' => _n ("IP address " , "IP addresses " , 1 ));
125135
126136 foreach ($ input as $ key => $ value ) {
127137 if (isset ($ mandatory_fields [$ key ])) {
128138 if ((isset ($ value ) && empty ($ value )) || !isset ($ value )) {
129- $ msg [$ key ] = $ mandatory_fields [$ key ];
139+ $ msg [$ key ] = $ mandatory_fields [$ key ];
130140 $ checkKo = true ;
131141 }
132142 }
@@ -141,98 +151,99 @@ function checkMandatoryFields($input) {
141151
142152 /**
143153 * Show form
144- *
154+ *
145155 * @param type $ip
146156 * @param type $id_addressing
147157 */
148- function showForm ($ ip , $ id_addressing , $ randmodal ) {
158+ function showForm ($ ip , $ id_addressing , $ randmodal )
159+ {
149160 global $ CFG_GLPI ;
150-
161+
151162 $ this ->forceTable (PluginAddressingAddressing::getTable ());
152163 $ this ->initForm (-1 );
153- $ options ['colspan ' ]= 2 ;
164+ $ options ['colspan ' ] = 2 ;
154165 $ this ->showFormHeader ($ options );
155166
156- echo "<input type='hidden' name='ip' value=' " . $ ip. "' /> " ;
157- echo "<input type='hidden' name='id_addressing' value=' " . $ id_addressing. "' /> " ;
167+ echo "<input type='hidden' name='ip' value=' " . $ ip . "' /> " ;
168+ echo "<input type='hidden' name='id_addressing' value=' " . $ id_addressing . "' /> " ;
158169 echo "<tr class='tab_bg_1'>
159- <td> ". _n ("IP address " , "IP addresses " , 1 ). "</td>
160- <td> ". $ ip. "</td>
170+ <td> " . _n ("IP address " , "IP addresses " , 1 ) . "</td>
171+ <td> " . $ ip . "</td>
161172 <td> " ;
162173 $ config = new PluginAddressingConfig ();
163174 $ config ->getFromDB ('1 ' );
164175 $ system = $ config ->fields ["used_system " ];
165176
166- $ ping_equip = new PluginAddressingPing_Equipment ();
177+ $ ping_equip = new PluginAddressingPing_Equipment ();
167178 list ($ message , $ error ) = $ ping_equip ->ping ($ system , $ ip );
168179 if ($ error ) {
169- echo "<img src= \"" . $ CFG_GLPI ["root_doc " ]. "/pics/ok.png \" alt= \"ok \"> " ;
180+ echo "<img src= \"" . $ CFG_GLPI ["root_doc " ] . "/pics/ok.png \" alt= \"ok \"> " ;
170181 _e ('Ping: ip address free ' , 'addressing ' );
171- }else {
172- echo "<img src= \"" . $ CFG_GLPI ["root_doc " ]. "/pics/warning.png \" alt= \"warning \"> " ;
182+ } else {
183+ echo "<img src= \"" . $ CFG_GLPI ["root_doc " ] . "/pics/warning.png \" alt= \"warning \"> " ;
173184 _e ('Ping: not available IP address ' , 'addressing ' );
174185 }
175186
176187 echo "</td></tr> " ;
177188 echo "<tr class='tab_bg_1'>
178- <td> ". __ ("Entity " ). "</td>
189+ <td> " . __ ("Entity " ) . "</td>
179190 <td> " ;
180-
191+
181192 $ rand = Entity::dropdown (array ('name ' => 'entities_id ' , 'entity ' => $ _SESSION ["glpiactiveentities " ]));
182-
193+
183194 $ params = array ('action ' => 'networkip ' , 'entities_id ' => '__VALUE__ ' );
184- Ajax::updateItemOnEvent ("dropdown_entities_id " . $ rand , 'networkip ' , $ CFG_GLPI ["root_doc " ]. "/plugins/addressing/ajax/addressing.php " , $ params );
195+ Ajax::updateItemOnEvent ("dropdown_entities_id " . $ rand , 'networkip ' , $ CFG_GLPI ["root_doc " ] . "/plugins/addressing/ajax/addressing.php " , $ params );
185196 echo "</td><td></td> " ;
186197 echo "</tr> " ;
187-
198+
188199 echo "</tr> " ;
189200 echo "<tr class='tab_bg_1'>
190- <td> ". __ ("Type " ). "</td>
201+ <td> " . __ ("Type " ) . "</td>
191202 <td> " ;
192- Dropdown::showFromArray ('type ' ,array (PluginAddressingReserveip::COMPUTER => Computer::getTypeName (),
193- PluginAddressingReserveip::NETWORK => NetworkEquipment::getTypeName (),
194- PluginAddressingReserveip::PRINTER => Printer::getTypeName ()), array ('on_change ' => "nameIsThere( \"" . $ CFG_GLPI ['root_doc ' ]. "\"); " ));
203+ Dropdown::showFromArray ('type ' , array (PluginAddressingReserveip::COMPUTER => Computer::getTypeName (),
204+ PluginAddressingReserveip::NETWORK => NetworkEquipment::getTypeName (),
205+ PluginAddressingReserveip::PRINTER => Printer::getTypeName ()), array ('on_change ' => "nameIsThere( \"" . $ CFG_GLPI ['root_doc ' ] . "\"); " ));
195206 echo "</td><td></td> " ;
196207 echo "</tr> " ;
197208 echo "<tr class='tab_bg_1'>
198- <td> ". __ ("Name " ). " : </td><td> " ;
199- $ option = array ('option ' => "onChange= \"javascript:nameIsThere(' " . $ CFG_GLPI ['root_doc ' ]. "'); \"" );
200- Html::autocompletionTextField ($ this ,"name " ,$ option );
209+ <td> " . __ ("Name " ) . " : </td><td> " ;
210+ $ option = array ('option ' => "onChange= \"javascript:nameIsThere(' " . $ CFG_GLPI ['root_doc ' ] . "'); \"" );
211+ Html::autocompletionTextField ($ this , "name " , $ option );
201212 echo "</td><td><div style= \"display: none; \" id='nameItem'> " ;
202- echo "<img src= \"" . $ CFG_GLPI ["root_doc " ]. "/pics/warning.png \" alt= \"warning \"> " ;
213+ echo "<img src= \"" . $ CFG_GLPI ["root_doc " ] . "/pics/warning.png \" alt= \"warning \"> " ;
203214 _e ('Name already in use ' , 'addressing ' );
204215 echo "</div></td>
205216 </tr> " ;
206-
217+
207218 echo "<tr class='tab_bg_1'>
208- <td> ". __ ("Status " ). " : </td>
219+ <td> " . __ ("Status " ) . " : </td>
209220 <td> " ;
210- Dropdown::show ("State " );
211- echo "</td>
221+ Dropdown::show ("State " );
222+ echo "</td>
212223 <td></td> </tr> " ;
213-
224+
214225 echo "<tr class='tab_bg_1'>
215- <td> ". __ ("MAC address " ). " :</td>
226+ <td> " . __ ("MAC address " ) . " :</td>
216227 <td><input type='text' name='mac' value='' size='40' /></td>
217228 <td></td></tr> " ;
218229 echo "<tr class='tab_bg_1'>
219- <td> ". __ ("Network " ). " :</td>
230+ <td> " . __ ("Network " ) . " :</td>
220231 <td><div id='networkip'> " ;
221232 IPNetwork::showIPNetworkProperties ($ _SESSION ["glpiactive_entity " ]);
222233 echo "</div></td>
223234 <td></td></tr> " ;
224235 echo "<tr class='tab_bg_1'>
225- <td> ". __ ("Comments " ). " :</td>
236+ <td> " . __ ("Comments " ) . " :</td>
226237 <td colspan='2'><textarea cols='75' rows='5' name='comment' ></textarea></td>
227238 </tr> " ;
228- echo "<tr class='tab_bg_1'>
239+ echo "<tr class='tab_bg_1'>
229240 <td colspan='4' class='center'>
230- <input type='submit' name='add' class='submit' value=' ". __ ("Validate the reservation " , 'addressing ' ). "' "
231- . "onclick= \"" . Html::jsGetElementbyID ("reserveip " . $ randmodal ). ".dialog('close');window.location.reload();return true; \"/>
241+ <input type='submit' name='add' class='submit' value=' " . __ ("Validate the reservation " , 'addressing ' ) . "' "
242+ . "onclick= \"" . Html::jsGetElementbyID ("reserveip " . $ randmodal ) . ".dialog('close');window.location.reload();return true; \"/>
232243 </td>
233244 </tr>
234245 </table> " ;
235246 Html::closeForm ();
236247 }
237-
248+
238249}
0 commit comments