1 <?php
3 class glpiAccount extends plugin
4 {
5 /* CLI vars */
6 var $cli_summary= "Manage server basic objects";
7 var $cli_description= "Some longer text\nfor help";
8 var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
10 /* attribute list for save action */
11 var $ignore_account= FALSE;
12 var $attributes= array("ID","name","contact",
13 "tech_num","comments","date_mod","os","location","domain","network","contact_num",
14 "model","type","is_template","FK_glpi_enterprise","deleted");
16 var $ID ; // Is set if this entry is edited
17 var $name = ""; // This should be the dn of this entry
18 var $contact = ""; // Empty
20 var $comments = ""; // Comment
22 var $contact_num = ""; // Contact person
23 var $tech_num = ""; // Technical responsible person
25 var $addUser = ""; // This is used to remember if a dialog was opened for tech_num or contact_num
27 var $date_mod = ""; // Modification timestamp
28 var $os = 0; // Operating system
29 var $location = 0; // Not used yet
30 var $domain = 0; // ? Set to 0
31 var $network = 0; // ? Set to 0
33 var $model = 0; // ? Can't remember this, it isn't used in GOsa
34 var $type = 0; // System type id
35 var $is_template = 0; // Used as template ?
36 var $FK_glpi_enterprise = 0; // Manufacturer id
37 var $deleted = "N"; // Deleted entries should have this set to Y
39 var $renameTypeDialog = false;
40 var $renameOSDialog = false;
41 var $select_type ;
43 /* Not necessary, cause we use mysql databse */
44 var $objectclasses= array("whatever");
46 /* Used to remember if this was an account (simply: is this an edited entry) */
47 var $initialy_was_account = false;
49 /* Remember current dialog */
50 var $edit_type = false;
51 var $edit_os = false;
53 var $data;
54 var $handle = NULL; // Glpi class handle used to query database
56 var $cur_dialog = NULL; // This contains the sub dialog handle
58 var $orig_dn; // To check if dn, has changed
59 var $ui; // Some GOsa specific user informations
61 var $usedDevices = array(); // Which devices are currently selected
62 var $usedAttachments = array(); // Used Attachments
64 /* Contructor
65 Sets default values and checks if we already have an existing glpi account
66 */
67 function glpiAccount ($config, $dn= NULL, $parent= NULL)
68 {
69 plugin::plugin ($config, $dn, $parent);
70 $this->ui= get_userinfo();
72 /* Abort class construction, if no db is defined */
73 if(!isset($this->config->data['SERVERS']['GLPI'])){
74 return;
75 }
77 // Get informations about databse connection
78 $this->data = $this->config->data['SERVERS']['GLPI'];
80 // Abort if mysql extension is missing
81 if(!is_callable("mysql_connect")){
82 return;
83 }
85 // Create handle of glpi class, and check if database connection is established
86 $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
88 if(!$this->handle->is_connected){
89 return;
90 }
92 // If this dn is already used in database, then get all informations for this entry
93 if($this->handle->is_account($this->dn)){
94 $this->is_account = true;
95 $tmp = ($this->handle->getComputerInformations($this->dn));
97 foreach(array("tech_num","os","FK_glpi_enterprise","type","comments","contact_num") as $attr){
98 $this->$attr = $tmp[0][$attr];
99 }
100 $this->usedDevices = $this->handle->getUsedDevices($tmp[0]['ID']);
101 $atts = $this->handle->getAssignAttachments($tmp[0]['ID']);
102 foreach($atts as $attachment){
104 $this->usedAttachments[$attachment['FK_doc']]=$attachment['FK_doc'];
105 }
106 }else{
107 $this->is_account = false;
108 }
110 /* set defaults */
111 $this->name = $this->dn;
112 $this->orig_dn = $this->dn;
113 $this->initialy_was_account = $this->is_account;
116 }
118 function execute()
119 {
120 /* Call parent execute */
121 plugin::execute();
123 /* Fill templating stuff */
124 $smarty= get_smarty();
125 $display= "";
127 /* Assign smarty defaults
128 To avoid undefined indexes, if there is an error with the glpi db
129 */
130 foreach(array("SystemTypes","SystemTypeKeys","Manufacturers",
131 "OSs","TechnicalResponsibles","InstalledDevices","Attachments","AttachmentKeys",
132 "OSKeys","OSs","ManufacturerKeys","InstalledDeviceKeys") as $attr){
133 $smarty->assign($attr,array());
134 }
135 foreach(array("type","FK_glpi_enterprise","os","tech_num","comments","contact_num","AttachmentsDiv") as $attr){
136 $smarty->assign($attr,"");
137 }
139 $tmp = $this->plInfo();
140 foreach($tmp['plProvidedAcls'] as $name => $translation) {
141 $smarty->assign($name."ACL",$this->getacl($name));
142 }
144 /* Check if there is a glpi database server defined
145 */
146 if(!isset($this->config->data['SERVERS']['GLPI'])){
147 print_red(_("There is no server with valid glpi database service."));
148 return($smarty->fetch(get_template_path('glpi.tpl', TRUE)));
149 }
151 $this->data = $this->config->data['SERVERS']['GLPI'];
153 /* Check if we can call mysql_connect
154 If we can't, there is no the mysql-php extension
155 */
156 if(!is_callable("mysql_connect")){
157 print_red(_("Can't connect to glpi database, the php-mysql extension is missing."));
158 return($smarty->fetch(get_template_path('glpi.tpl', TRUE)));
159 }
161 $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
163 /* If handle == false, abort
164 Seems that the server, username and or password is wrong
165 */
166 if(!$this->handle->is_connected){
167 print_red(_("Can't connect to glpi database, check configuration twice."));
168 return($smarty->fetch(get_template_path('glpi.tpl', TRUE)));
169 }
171 /* All checks are ok
172 Lets handle Posts, templates etc below ...
173 */
175 $users = $this->handle->getUsers();
176 $ldap= $this->config->get_ldap_link();
178 /* Check for Trading button Post
179 */
180 if(isset($_POST['Trading'])){
181 print_red(_("This feature is not implemented yet."));
182 }
184 /* Check for Software button Post
185 */
186 if(isset($_POST['Software'])){
187 print_red(_("This feature is not implemented yet."));
188 }
190 /* Check for Contract button Post
191 */
192 if(isset($_POST['Contracts'])){
193 print_red(_("This feature is not implemented yet."));
194 }
196 /* Add Device was requested, open new dialog
197 */
198 if((isset($_POST['AddDevice'])) && ($this->acl_is_writeable("Devices"))){
199 $this->dialog =true;
200 $this->cur_dialog = new glpiDeviceManagement($this->config,$this->dn,$this->usedDevices);
201 }
203 /* Attachment pool was closed with use
204 */
205 if(isset($_POST['UseAttachment']) && ($this->acl_is_writeable("Attachments"))){
206 if(count($this->cur_dialog->check())){
207 foreach($this->cur_dialog->check() as $msg){
208 print_red($msg);
209 }
210 }else{
211 $this->cur_dialog->save_object();
212 $this->usedAttachments = $this->cur_dialog->save();
213 $this->cur_dialog = false;
214 $this->edit_type = false;
215 }
216 }
218 /* Attachment pool was closed with abort
219 */
220 if(isset($_POST['AbortAttachment'])){
221 $this->cur_dialog = false;
222 $this->edit_type = false;
223 }
225 /* Open Attachment pool to add/edit Attachments
226 */
227 if(isset($_POST['AddAttachment']) && ($this->acl_is_writeable("Attachments"))){
228 $this->cur_dialog = new glpiAttachmentPool($this->config,$this->dn,$this->usedAttachments);
229 $this->dialog = true;
230 }
232 /* Remove Attachment fro this tab
233 */
234 $once = true;
235 foreach($_POST as $name => $value){
236 if((preg_match("/^delAttachment_/",$name))&&($once) && $this->acl_is_writeable("Attachments")){
237 $once= false;
238 $name = preg_replace("/^delAttachment_/","",$name);
239 $entry = preg_replace("/_.*$/","",$name);
240 if(isset($this->usedAttachments[$entry])){
241 unset($this->usedAttachments[$entry]);
242 }
243 }
244 }
245 if((isset($_POST['RemoveAttachment']))&&(isset($_POST['Attachments'])) && ($this->acl_is_writeable("Attachments"))){
246 foreach($_POST['Attachments'] as $entry){
247 if(isset($this->usedAttachments[$entry])){
248 unset($this->usedAttachments[$entry]);
249 }
250 }
251 }
253 /* We have selected some devices and pressed use button
254 */
255 if(isset($_POST['SelectDeviceSave']) && $this->acl_is_writeable("Devices")){
256 $this->cur_dialog->save_object();
257 $this->usedDevices= ($this->cur_dialog->getSelected());
258 $this->cur_dialog = false;
259 $this->dialog = false;
260 $this->edit_type=false;
261 }
263 /* Aborted Device selction
264 */
265 if(isset($_POST['SelectDeviceCancel']) && ($this->acl_is_writeable("Devices"))){
266 $this->dialog = false;
267 $this->cur_dialog = false;
268 $this->edit_type=false;
269 }
271 /* System type management
272 */
273 if(isset($_POST['edit_type']) && $this->acl->acl_is_writeable("type")){
274 $this->dialog = true;
275 $this->edit_type=true;
276 }
278 /* This closes the system type editing dialog
279 */
280 if(isset($_POST['close_edit_type']) && ($this->acl_is_writeable("type"))){
281 $this->edit_type=false;
282 $this->dialog = false;
283 }
285 if(isset($_POST['Rename_Cancel'])){
286 $this->renameTypeDialog = false;
287 $this->renameOSDialog = false;
288 }
290 /* This appends a new system to our sytem types
291 */
292 if((isset($_POST['add_type']))&&(!empty($_POST['type_string'])) && $this->acl_is_writeable("type")){
293 $attr = $this->handle->getSystemTypes();
294 if(in_array(trim($_POST['type_string']),$attr)){
295 print_red(_("Adding new sytem type failed, this system type name is already used.")) ;
296 }else{
297 $this->handle->addSystemType(trim($_POST['type_string']));
298 }
299 }
301 /* Remove selected type from our system types list
302 */
303 if((isset($_POST['del_type']))&&(!empty($_POST['select_type'])) && $this->acl_is_writeable("type")){
304 $tmp = $this->handle->is_systemTypeUsed($_POST['select_type']);
305 if(count($tmp)){
306 $names = "";
307 foreach($tmp as $name){
308 $names .= ", ".$name;
309 }
310 $names = preg_replace("/^, /","",$names);
311 $names = trim($names);
312 if(count($tmp) == 3){
313 $names .= " ...";
314 }
315 print_red(sprintf(_("You can't delete this system type, it is still in use by these system(s) '%s'"),$names));
316 }else{
317 $this->handle->removeSystemType($_POST['select_type']);
318 }
319 }
321 /* Rename selected system type to given string
322 */
323 if(isset($_POST['Rename_type_OK'])){
324 $attr = $this->handle->getSystemTypes();
325 if(in_array(trim($_POST['string']),$attr)){
326 print_red(_("Rename failed, this system type name is already used.")) ;
327 }else{
328 $this->renameTypeDialog = false;
329 $this->handle->updateSystemType($_POST['string'],trim($this->select_type));
330 }
331 }
334 if((isset($_POST['rename_type'])&&(!empty($_POST['select_type'])))||($this->renameTypeDialog)){
335 if(isset($_POST['select_type'])){
336 $this->select_type = $_POST['select_type'];
337 }
338 $this->renameTypeDialog = true;
339 $tmp = $this->handle->getSystemTypes();
341 $smarty->assign("string",$tmp[$this->select_type]);
342 if(isset($_POST['string'])){
343 $smarty->assign("string",$_POST['string']);
344 }
345 $smarty->assign("Method","rename");
346 $display= $smarty->fetch(get_template_path('glpi_edit_type.tpl', TRUE));
347 return($display);
348 }
352 /* Someone wants to edit the system types ...
353 So, lets open a new dialog which provides some buttons to edit the types
354 */
355 if($this->edit_type){
356 $smarty->assign("Method","edit");
357 $smarty->assign("SystemTypes", $this->handle->getSystemTypes());
358 $smarty->assign("SystemTypeKeys", array_flip($this->handle->getSystemTypes()));
359 $display= $smarty->fetch(get_template_path('glpi_edit_type.tpl', TRUE));
360 return($display);
361 }
363 /* System os management
364 */
365 if(isset($_POST['edit_os']) && $this->acl_is_writeable("os")){
366 $this->dialog = true;
367 $this->edit_os=true;
368 }
370 /* Close Operating system dialog
371 */
372 if(isset($_POST['close_edit_os'])){
373 $this->edit_os=false;
374 $this->dialog = false;
375 }
377 /* Add new os to the db
378 */
379 if((isset($_POST['add_os']))&&(!empty($_POST['is_string'])) && $this->acl_is_writeable("os")){
380 $attr = $this->handle->getOSTypes();
381 if(in_array(trim($_POST['is_string']),$attr)){
382 print_red(_("Adding new operating system failed, specifed name is already used.")) ;
383 }else{
384 $this->handle->addOS(trim($_POST['is_string']));
385 }
386 }
388 /* Delete selected os from list and db
389 */
390 if((isset($_POST['del_os']))&&(!empty($_POST['select_os'])) && $this->acl_is_writeable("os")){
391 $tmp = $this->handle->is_osUsed($_POST['select_os']);
393 if(count($tmp)){
395 $names = "";
396 foreach($tmp as $name){
397 $names .= ", ".$name;
398 }
399 $names = preg_replace("/^, /","",$names);
400 $names = trim($names);
401 if(count($tmp) == 3){
402 $names .= " ...";
403 }
404 print_red(sprintf(_("You can't delete this operating system, it is still in use by these system(s) '%s'"),$names));
406 }else{
407 $this->handle->removeOS_byID($_POST['select_os']);
408 }
409 }
411 /* Rename selected os to given string
412 */
413 if(isset($_POST['Rename_os_OK']) && $this->acl_is_writeable("os")){
414 $attr = $this->handle->getOSTypes();
415 if(in_array(trim($_POST['string']),$attr)){
416 print_red(_("Updating operating system failed, specifed name is already used.")) ;
417 }else{
418 $this->handle->updateOS($_POST['string'],$this->select_type);
419 $this->renameOSDialog = false;
420 }
421 }
422 if((isset($_POST['rename_os'])&&(!empty($_POST['select_os'])))||($this->renameOSDialog)){
423 if(isset($_POST['select_os'])){
424 $this->select_type = $_POST['select_os'];
425 }
426 $this->renameOSDialog = true;
427 $tmp = $this->handle->getOSTypes();
429 $smarty->assign("string",$tmp[$this->select_type]);
430 if(isset($_POST['string'])){
431 $smarty->assign("string",$_POST['string']);
432 }
433 $smarty->assign("Method","rename");
434 $display= $smarty->fetch(get_template_path('glpi_edit_os.tpl', TRUE));
435 return($display);
436 }
438 /* Open dialog to edit os types
439 */
440 if($this->edit_os){
441 $smarty->assign("Method","edit");
442 $smarty->assign("OSs", $this->handle->getOSTypes());
443 $smarty->assign("OSKeys", array_flip($this->handle->getOSTypes()));
444 $display= $smarty->fetch(get_template_path('glpi_edit_os.tpl', TRUE));
445 return($display);
446 }
450 /* Show dialog to select a new contact person
451 * Select a contact person
452 */
453 if(isset($_POST['SelectContactPerson']) && $this->acl_is_writeable("contact_num")){
454 $this->addUser = "contact";
455 $this->cur_dialog= new glpiSelectUser($this->config,$this->dn,"user_tech_num");
456 }
458 /* Open dialog which allows to edit the manufacturers
459 */
460 if(isset($_POST['edit_manufacturer']) && $this->acl_is_writeable("FK_glpi_enterprise")){
461 $this->cur_dialog = new glpiManufacturer($this->config,$this->dn);
462 $this->dialog = true;
463 }
465 /* Close manufacturer editing dialog
466 */
467 if(isset($_POST['close_edit_manufacturer'])){
468 $this->dialog = false;
469 $this->cur_dialog = false;
470 }
472 /* Abort user selection
473 */
474 $smarty->assign("AbortSelectUser","SelectUserCancel");
475 if(isset($_POST['SelectUserCancel'])){
476 $this->dialog = false;
477 $this->addUser ="";
478 $this->cur_dialog = false;
479 }
481 /* Selecte technical responsible person
482 */
483 if(isset($_POST['SelectTechPerson']) && $this->acl_is_writeable("tech_num")){
484 $this->addUser ="tech";
485 $this->cur_dialog= new glpiSelectUser($this->config,$this->dn,"user_tech_num");
486 }
488 /* Technical responsible person selected*/
489 if(isset($_GET['act'])&&($_GET['act']=="user_tech_num")){
491 /* Get posted id */
492 $id = base64_decode($_GET['id']);
494 /* Check if user is already created in glpi database */
495 if(!in_array($id,$users)){
497 /* If this user doesn't exists in glpi db, we must create him */
498 $ldap->cat($id, array('cn', 'mail', 'telephoneNumber'));
499 $atr = $ldap->fetch();
500 $tmp = array();
501 $use = array( "cn" =>"name",
502 "mail" =>"email",
503 "telephoneNumber" =>"phone");
505 /* Create array */
506 foreach($use as $gosa => $glpi){
507 if(isset($atr[$gosa])){
508 $tmp[$glpi]= $atr[$gosa][0];
509 }
510 }
512 /* Add this user */
513 $this->handle->addUser($tmp,$id);
514 }
516 /* Re-read users */
517 $users = ($this->handle->getUsers());
519 /* Get user */
520 $tmp = array_flip($users);
521 $id=$tmp[$id];
523 /* Use user id, close dialog */
524 if($this->addUser == "tech"){
525 $this->tech_num = $id;
526 }else{
527 $this->contact_num = $id;
528 }
529 $this->cur_dialog = false;
530 $this->dialog= false;
531 }
533 /* if( cur_dialog != false || cur_dialog != NULL)
534 * There is a dialog which wants to be displayed
535 */
536 if($this->cur_dialog){
537 $this->cur_dialog->save_object();
538 $this->dialog=true;
539 $this->cur_dialog->parent = &$this;
540 return($this->cur_dialog->execute());
541 }else{
542 $this->dialog= false;
543 }
545 /* Assign smarty defaults */
546 foreach(array("SystemTypes","SystemTypeKeys","Manufacturers","OSs","TechnicalResponsibles","InstalledDevices","Attachments") as $attr){
547 $smarty->assign($attr,array());
548 }
550 /* Assign some vars to smarty
551 */
552 foreach(array("type","FK_glpi_enterprise","os","tech_num","contact_num","Attachments","InstalledDevices") as $attr){
553 $smarty->assign($attr,"");
554 }
556 /* Do we need to flip is_account state? */
557 if(isset($_POST['modify_state'])){
558 if($this->is_account && $this->acl_is_removeable()){
559 $this->is_account= FALSE;
560 }elseif(!$this->is_account && $this->acl_is_createable()){
561 $this->is_account= TRUE;
562 }
563 }
565 /* Show tab dialog headers */
566 if ($this->is_account){
567 $display= $this->show_disable_header(_("Remove inventory"),
568 _("This device has inventory informations enabled. You can disable them by clicking below."));
569 } else {
570 $display= $this->show_enable_header(_("Add inventory"),
571 _("This device has inventory informations disabled. You can enable them by clicking below."));
572 return ($display);
573 }
575 /* Assign system types
576 */
577 $smarty->assign("SystemTypeKeys", array_flip($this->handle->getSystemTypes()));
578 $smarty->assign("SystemTypes", $this->handle->getSystemTypes());
579 $smarty->assign("type", $this->type);
581 /* Assign os types
582 */
583 $smarty->assign("OSKeys", array_flip($this->handle->getOSTypes()));
584 $smarty->assign("OSs", $this->handle->getOSTypes());
585 $smarty->assign("os", $this->os);
587 /* Dispaly installed devices */
588 $smarty->assign("InstalledDevices" ,$this->getDevices());
589 $smarty->assign("InstalledDeviceKeys" ,array_flip($this->getDevices()));
591 /* Append manufacturers
592 */
593 $smarty->assign("ManufacturerKeys", array_flip($this->handle->getEnterprises()));
594 $smarty->assign("Manufacturers", $this->handle->getEnterprises());
595 $smarty->assign("FK_glpi_enterprise", $this->FK_glpi_enterprise);
597 /* Assign used Attachments
598 */
600 $divlist = new divSelectBox("glpiAttachmentsList");
601 $divlist-> SetHeight(130);
602 $atts = $this->getUsedAttachments(true);
603 $downlink = "<a href='get_attachment.php?id=%s' target='_blank'>%s</a>";
604 $del_link = "<input type='image' src='images/edittrash.png' name='delAttachment_%s'>";
605 foreach($atts as $id => $attachment){
606 $divlist->AddEntry
607 (
608 array(
609 array("string"=>$attachment['name']),
610 array("string"=>$attachment['mime']),
611 array("string"=>sprintf($downlink,$id,$attachment['filename'])),
612 array("string"=>sprintf($del_link,$attachment['ID']),"attach"=>"style='border-right:0px;'"),
613 )
614 );
615 }
617 $smarty->assign("AttachmentsDiv" ,$divlist->DrawList());
618 /* Handle contact person
619 Assign name ... to smarty, if set
620 */
621 if(isset($users[$this->contact_num])){
622 $ldap->cat($users[$this->contact_num], array('givenName', 'sn', 'uid'));
623 $tr = $ldap->fetch();
624 $str = "";
625 if(isset($tr['givenName'][0])){ $str .= $tr['givenName'][0]." "; }
626 if(isset($tr['sn'][0])) { $str .= $tr['sn'][0]." "; }
627 if(isset($tr['uid'][0])){ $str .= "[".$tr['uid'][0]."]"; }
628 $smarty->assign("contact_num", $str);
629 }else{
630 $smarty->assign("contact_num", _("N/A"));
631 }
633 /* Handle tech person
634 Assign name ... to smarty, if set
635 */
636 if(isset($users[$this->tech_num])){
637 $tr = $ldap->cat($users[$this->tech_num], array('givenName', 'sn', 'uid'));
638 $tr = $ldap->fetch();
639 $str = "";
640 if(isset($tr['givenName'][0])){ $str .= $tr['givenName'][0]." "; }
641 if(isset($tr['sn'][0])) { $str .= $tr['sn'][0]." "; }
642 if(isset($tr['uid'][0])){ $str .= "[".$tr['uid'][0]."]"; }
643 $smarty->assign("tech_num", $str);
644 }else{
645 $smarty->assign("tech_num", _("N/A"));
646 }
647 $smarty->assign("comments", $this->comments);
649 $display.= $smarty->fetch(get_template_path('glpi.tpl', TRUE));
650 return($display);
651 }
653 function remove_from_parent()
654 {
655 /* Cancel if there's nothing to do here */
656 if ((!$this->initially_was_account) || (!$this->acl_is_removeable())){
657 return;
658 }
659 if(function_exists("mysql_pconnect")){
660 $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
661 if($this->initialy_was_account){
662 $this->handle->removeComputerInformations($this->dn);
663 }
664 }else{
665 print_red(_("Can't remove glpi account, while mysql extension is missing."));
666 }
668 }
670 function getDevices(){
671 $ret = array();
672 foreach($this->usedDevices as $type => $entries){
673 foreach($entries as $ent){
674 if(isset($ent['designation'])){
675 $ret[] = $ent['designation']." [".$type."]";
676 }else{
677 $ret[] = $ent['name']." [".$type."]";
678 }
679 }
680 }
681 return($ret);
682 }
685 /* Save data to object */
686 function save_object()
687 {
688 if(!isset($_POST['glpi_tpl_posted'])) {
689 return ;
690 }
691 plugin::save_object();
692 }
695 /* Check supplied data */
696 function check()
697 {
698 /* Call common method to give check the hook */
699 $message= plugin::check();
701 // if($this->TechnicalResponsible == ""){
702 // $message[] = _("Please select a technical responsible person for this entry.");
703 // }
705 return ($message);
706 }
708 /* Save to LDAP */
709 function save()
710 {
711 if($this->is_account){
712 $attrs = array();
713 $this->date_mod = date("Y-m-d H:i:s");
714 foreach($this->attributes as $attr){
715 $attrs[$attr] = $this->$attr;
716 }
717 $attrs['name'] = $this->dn;
718 unset($attrs['ID']);
719 $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
721 /* check if we have to update, add */
722 if($this->initialy_was_account&&$this->is_account){
723 $this->handle->updateComputerInformations($attrs,$this->orig_dn);
724 }elseif($this->is_account){
725 $this->handle->addComputerInformations($attrs,$this->dn);
726 }
727 $tmp = $this->handle->getComputerInformations($this->dn);
728 $this->handle->addDevicesToComputer($this->usedDevices,$tmp[0]['ID']);
729 }
730 }
732 /* Return used attachments */
733 function getUsedAttachments($divlist = false)
734 {
735 $atts =$this->handle->getAttachments();
736 $ret = array();
737 foreach($atts as $entry){
738 if(in_array($entry['ID'],$this->usedAttachments)){
739 if($divlist){
740 $ret[$entry['ID']] = $entry;
741 }else{
742 $cm ="";
743 if(isset($entry['comment'])){
744 $cm=" [".$entry['comment']."]";
745 }
746 if(isset($entry['mime'])){
747 $cm.=" -".$entry['mime']."";
748 }
750 $ret[$entry['ID']]= $entry['name'].$cm;
751 }
752 }
753 }
754 return($ret);
755 }
757 /* Return plugin informations for acl handling */
758 function plInfo()
759 {
760 return (array(
761 "plShortName" => _("Glpi"),
762 "plDescription" => _("Inventory extension"),
763 "plSelfModify" => FALSE,
764 "plDepends" => array(),
765 "plPriority" => 0,
766 "plSection" => array("administration"),
767 "plCategory" => array("workstation","terminal","component","server","phone") ,
768 "plProvidedAcls"=> array(
770 "tech_num" => _("Technical responsible"),
771 "comments" => _("Comment"),
772 "os" => _("Operating system"),
773 "location" => _("Location"),
774 "contact_num" => _("Contact person"),
775 "model" => _("Model"),
776 "type" => _("Type"),
777 "FK_glpi_enterprise" => _("Manufacturer"),
778 "Attachments" => _("Attachments"),
779 "Devices" => _("Peripheral devices"))
780 ));
781 }
784 }
786 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
787 ?>