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 $smarty->assign($attr."ACL"," disabled ");
135 }
136 foreach(array("type","FK_glpi_enterprise","os","tech_num","comments","contact_num","AttachmentsDiv") as $attr){
137 $smarty->assign($attr,"");
138 $smarty->assign($attr."ACL"," disabled ");
139 }
141 /* Check if there is a glpi database server defined
142 */
143 if(!isset($this->config->data['SERVERS']['GLPI'])){
144 print_red(_("There is no server with valid glpi database service."));
145 return($smarty->fetch(get_template_path('glpi.tpl', TRUE)));
146 }
148 $this->data = $this->config->data['SERVERS']['GLPI'];
150 /* Check if we can call mysql_connect
151 If we can't, there is no the mysql-php extension
152 */
153 if(!is_callable("mysql_connect")){
154 print_red(_("Can't connect to glpi database, the php-mysql extension is missing."));
155 return($smarty->fetch(get_template_path('glpi.tpl', TRUE)));
156 }
158 $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
160 /* If handle == false, abort
161 Seems that the server, username and or password is wrong
162 */
163 if(!$this->handle->is_connected){
164 print_red(_("Can't connect to glpi database, check configuration twice."));
165 return($smarty->fetch(get_template_path('glpi.tpl', TRUE)));
166 }
168 /* All checks are ok
169 Lets handle Posts, templates etc below ...
170 */
172 $users = $this->handle->getUsers();
173 $ldap= $this->config->get_ldap_link();
175 /* Check for Trading button Post
176 */
177 if(isset($_POST['Trading'])){
178 print_red(_("This feature is not implemented yet."));
179 }
181 /* Check for Software button Post
182 */
183 if(isset($_POST['Software'])){
184 print_red(_("This feature is not implemented yet."));
185 }
187 /* Check for Contract button Post
188 */
189 if(isset($_POST['Contracts'])){
190 print_red(_("This feature is not implemented yet."));
191 }
193 /* Add Device was requested, open new dialog
194 */
195 if(isset($_POST['AddDevice']) && chkacl($this->acl,"usedDevices") == ""){
196 $this->dialog =true;
197 $this->cur_dialog = new glpiDeviceManagement($this->config,$this->dn,$this->usedDevices);
198 }
200 /* Attachment pool was closed with use
201 */
202 if(isset($_POST['UseAttachment']) && chkacl($this->acl,"usedAttachments") == ""){
203 if(count($this->cur_dialog->check())){
204 foreach($this->cur_dialog->check() as $msg){
205 print_red($msg);
206 }
207 }else{
208 $this->cur_dialog->save_object();
209 $this->usedAttachments = $this->cur_dialog->save();
210 $this->cur_dialog = false;
211 $this->edit_type = false;
212 }
213 }
215 /* Attachment pool was closed with abort
216 */
217 if(isset($_POST['AbortAttachment'])){
218 $this->cur_dialog = false;
219 $this->edit_type = false;
220 }
222 /* Open Attachment pool to add/edit Attachments
223 */
224 if(isset($_POST['AddAttachment'])){
225 $this->cur_dialog = new glpiAttachmentPool($this->config,$this->dn,$this->usedAttachments);
226 $this->dialog = true;
227 }
229 /* Remove Attachment fro this tab
230 */
231 $once = true;
232 foreach($_POST as $name => $value){
233 if((preg_match("/^delAttachment_/",$name))&&($once) && chkacl($this->acl,"usedAttachments") == ""){
234 $once= false;
235 $name = preg_replace("/^delAttachment_/","",$name);
236 $entry = preg_replace("/_.*$/","",$name);
237 if(isset($this->usedAttachments[$entry])){
238 unset($this->usedAttachments[$entry]);
239 }
240 }
241 }
242 if((isset($_POST['RemoveAttachment']))&&(isset($_POST['Attachments'])) && chkacl($this->acl,"usedAttachments") == ""){
243 foreach($_POST['Attachments'] as $entry){
244 if(isset($this->usedAttachments[$entry])){
245 unset($this->usedAttachments[$entry]);
246 }
247 }
248 }
250 /* We have selected some devices and pressed use button
251 */
252 if(isset($_POST['SelectDeviceSave'])){
253 $this->cur_dialog->save_object();
254 $this->usedDevices= ($this->cur_dialog->getSelected());
255 $this->cur_dialog = false;
256 $this->dialog = false;
257 $this->edit_type=false;
258 }
260 /* Aborted Device selction
261 */
262 if(isset($_POST['SelectDeviceCancel'])){
263 $this->dialog = false;
264 $this->cur_dialog = false;
265 $this->edit_type=false;
266 }
268 /* System type management
269 */
270 if(isset($_POST['edit_type']) && chkacl($this->acl,"type") == ""){
271 $this->dialog = true;
272 $this->edit_type=true;
273 }
275 /* This closes the system type editing dialog
276 */
277 if(isset($_POST['close_edit_type'])){
278 $this->edit_type=false;
279 $this->dialog = false;
280 }
282 if(isset($_POST['Rename_Cancel'])){
283 $this->renameTypeDialog = false;
284 $this->renameOSDialog = false;
285 }
287 /* This appends a new system to our sytem types
288 */
289 if((isset($_POST['add_type']))&&(!empty($_POST['type_string'])) && chkacl($this->acl,"type") == ""){
290 $attr = $this->handle->getSystemTypes();
291 if(in_array(trim($_POST['type_string']),$attr)){
292 print_red(_("Adding new sytem type failed, this system type name is already used.")) ;
293 }else{
294 $this->handle->addSystemType(trim($_POST['type_string']));
295 }
296 }
298 /* Remove selected type from our system types list
299 */
300 if((isset($_POST['del_type']))&&(!empty($_POST['select_type'])) && chkacl($this->acl,"type") == ""){
301 $tmp = $this->handle->is_systemTypeUsed($_POST['select_type']);
302 if(count($tmp)){
303 $names = "";
304 foreach($tmp as $name){
305 $names .= ", ".$name;
306 }
307 $names = preg_replace("/^, /","",$names);
308 $names = trim($names);
309 if(count($tmp) == 3){
310 $names .= " ...";
311 }
312 print_red(sprintf(_("You can't delete this system type, it is still in use by these system(s) '%s'"),$names));
313 }else{
314 $this->handle->removeSystemType($_POST['select_type']);
315 }
316 }
318 /* Rename selected system type to given string
319 */
320 if(isset($_POST['Rename_type_OK'])){
321 $attr = $this->handle->getSystemTypes();
322 if(in_array(trim($_POST['string']),$attr)){
323 print_red(_("Rename failed, this system type name is already used.")) ;
324 }else{
325 $this->renameTypeDialog = false;
326 $this->handle->updateSystemType($_POST['string'],trim($this->select_type));
327 }
328 }
331 if((isset($_POST['rename_type'])&&(!empty($_POST['select_type'])))||($this->renameTypeDialog) && chkacl($this->acl,"type") == ""){
332 if(isset($_POST['select_type'])){
333 $this->select_type = $_POST['select_type'];
334 }
335 $this->renameTypeDialog = true;
336 $tmp = $this->handle->getSystemTypes();
338 $smarty->assign("string",$tmp[$this->select_type]);
339 if(isset($_POST['string'])){
340 $smarty->assign("string",$_POST['string']);
341 }
342 $smarty->assign("Method","rename");
343 $display= $smarty->fetch(get_template_path('glpi_edit_type.tpl', TRUE));
344 return($display);
345 }
349 /* Someone wants to edit the system types ...
350 So, lets open a new dialog which provides some buttons to edit the types
351 */
352 if($this->edit_type){
353 $smarty->assign("Method","edit");
354 $smarty->assign("SystemTypes", $this->handle->getSystemTypes());
355 $smarty->assign("SystemTypeKeys", array_flip($this->handle->getSystemTypes()));
356 $display= $smarty->fetch(get_template_path('glpi_edit_type.tpl', TRUE));
357 return($display);
358 }
360 /* System os management
361 */
362 if(isset($_POST['edit_os']) && chkacl($this->acl,"os") == ""){
363 $this->dialog = true;
364 $this->edit_os=true;
365 }
367 /* Close Operating system dialog
368 */
369 if(isset($_POST['close_edit_os'])){
370 $this->edit_os=false;
371 $this->dialog = false;
372 }
374 /* Add new os to the db
375 */
376 if((isset($_POST['add_os']))&&(!empty($_POST['is_string'])) && chkacl($this->acl,"os") == ""){
377 $attr = $this->handle->getOSTypes();
378 if(in_array(trim($_POST['is_string']),$attr)){
379 print_red(_("Adding new operating system failed, specifed name is already used.")) ;
380 }else{
381 $this->handle->addOS(trim($_POST['is_string']));
382 }
383 }
385 /* Delete selected os from list and db
386 */
387 if((isset($_POST['del_os']))&&(!empty($_POST['select_os'])) && chkacl($this->acl,"os") == ""){
388 $tmp = $this->handle->is_osUsed($_POST['select_os']);
390 if(count($tmp)){
392 $names = "";
393 foreach($tmp as $name){
394 $names .= ", ".$name;
395 }
396 $names = preg_replace("/^, /","",$names);
397 $names = trim($names);
398 if(count($tmp) == 3){
399 $names .= " ...";
400 }
401 print_red(sprintf(_("You can't delete this operating system, it is still in use by these system(s) '%s'"),$names));
403 }else{
404 $this->handle->removeOS_byID($_POST['select_os']);
405 }
406 }
408 /* Rename selected os to given string
409 */
410 if(isset($_POST['Rename_os_OK'])){
411 $attr = $this->handle->getOSTypes();
412 if(in_array(trim($_POST['string']),$attr)){
413 print_red(_("Updating operating system failed, specifed name is already used.")) ;
414 }else{
415 $this->handle->updateOS($_POST['string'],$this->select_type);
416 $this->renameOSDialog = false;
417 }
418 }
419 if((isset($_POST['rename_os'])&&(!empty($_POST['select_os'])))||($this->renameOSDialog) && chkacl($this->acl,"os") == ""){
420 if(isset($_POST['select_os'])){
421 $this->select_type = $_POST['select_os'];
422 }
423 $this->renameOSDialog = true;
424 $tmp = $this->handle->getOSTypes();
426 $smarty->assign("string",$tmp[$this->select_type]);
427 if(isset($_POST['string'])){
428 $smarty->assign("string",$_POST['string']);
429 }
430 $smarty->assign("Method","rename");
431 $display= $smarty->fetch(get_template_path('glpi_edit_os.tpl', TRUE));
432 return($display);
433 }
435 /* Open dialog to edit os types
436 */
437 if($this->edit_os && chkacl($this->acl,"os") == ""){
438 $smarty->assign("Method","edit");
439 $smarty->assign("OSs", $this->handle->getOSTypes());
440 $smarty->assign("OSKeys", array_flip($this->handle->getOSTypes()));
441 $display= $smarty->fetch(get_template_path('glpi_edit_os.tpl', TRUE));
442 return($display);
443 }
447 /* Show dialog to select a new contact person
448 * Select a contact person
449 */
450 if(isset($_POST['SelectContactPerson']) && chkacl($this->acl,"user_tech_num") == ""){
451 $this->addUser = "contact";
452 $this->cur_dialog= new glpiSelectUser($this->config,$this->dn,"user_tech_num");
453 }
455 /* Open dialog which allows to edit the manufacturers
456 */
457 if(isset($_POST['edit_manufacturer']) && chkacl($this->acl,"user_tech_num") == ""){
458 $this->cur_dialog = new glpiManufacturer($this->config,$this->dn);
459 $this->dialog = true;
460 }
462 /* Close manufacturer editing dialog
463 */
464 if(isset($_POST['close_edit_manufacturer'])){
465 $this->dialog = false;
466 $this->cur_dialog = false;
467 }
469 /* Abort user selection
470 */
471 $smarty->assign("AbortSelectUser","SelectUserCancel");
472 if(isset($_POST['SelectUserCancel'])){
473 $this->dialog = false;
474 $this->addUser ="";
475 $this->cur_dialog = false;
476 }
478 /* Selecte technical responsible person
479 */
480 if(isset($_POST['SelectTechPerson']) && chkacl($this->acl,"user_tech_num") == ""){
481 $this->addUser ="tech";
482 $this->cur_dialog= new glpiSelectUser($this->config,$this->dn,"user_tech_num");
483 }
485 /* Technical responsible person selected*/
486 if(isset($_GET['act'])&&($_GET['act']=="user_tech_num") && chkacl($this->acl,"user_tech_num") == ""){
488 /* Get posted id */
489 $id = base64_decode($_GET['id']);
491 /* Check if user is already created in glpi database */
492 if(!in_array($id,$users)){
494 /* If this user doesn't exists in glpi db, we must create him */
495 $ldap->cat($id, array('cn', 'mail', 'telephoneNumber'));
496 $atr = $ldap->fetch();
497 $tmp = array();
498 $use = array( "cn" =>"name",
499 "mail" =>"email",
500 "telephoneNumber" =>"phone");
502 /* Create array */
503 foreach($use as $gosa => $glpi){
504 if(isset($atr[$gosa])){
505 $tmp[$glpi]= $atr[$gosa][0];
506 }
507 }
509 /* Add this user */
510 $this->handle->addUser($tmp,$id);
511 }
513 /* Re-read users */
514 $users = ($this->handle->getUsers());
516 /* Get user */
517 $tmp = array_flip($users);
518 $id=$tmp[$id];
520 /* Use user id, close dialog */
521 if($this->addUser == "tech"){
522 $this->tech_num = $id;
523 }else{
524 $this->contact_num = $id;
525 }
526 $this->cur_dialog = false;
527 $this->dialog= false;
528 }
530 /* if( cur_dialog != false || cur_dialog != NULL)
531 * There is a dialog which wants to be displayed
532 */
533 if($this->cur_dialog){
534 $this->cur_dialog->save_object();
535 $this->dialog=true;
536 $this->cur_dialog->parent = &$this;
537 return($this->cur_dialog->execute());
538 }else{
539 $this->dialog= false;
540 }
542 /* Assign smarty defaults */
543 foreach(array("SystemTypes","SystemTypeKeys","Manufacturers","OSs","TechnicalResponsibles","InstalledDevices","Attachments") as $attr){
544 $smarty->assign($attr,array());
545 }
547 foreach($this->attributes as $attr){
548 $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
549 }
551 /* Assign some vars to smarty
552 */
553 foreach(array("type","FK_glpi_enterprise","os","tech_num","contact_num","Attachments","InstalledDevices") as $attr){
554 $smarty->assign($attr,"");
555 $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
556 }
558 /* Do we need to flip is_account state? */
560 if (isset($_POST['modify_state'])){
562 /* Only change account state if allowed */
563 if($this->is_account && $this->acl == "#all#"){
564 $this->is_account= !$this->is_account;
565 $this->is_modified = true;
566 }elseif(!$this->is_account && chkacl($this->acl,"create") == "" ){
567 $this->is_account= !$this->is_account;
568 $this->is_modified = true;
569 }
570 }
572 /* Show tab dialog headers */
573 if ($this->is_account){
574 $display= $this->show_header(_("Remove inventory"),
575 _("This device has inventory informations enabled. You can disable them by clicking below."));
576 } else {
577 $display= $this->show_header(_("Add inventory"),
578 _("This device has inventory informations disabled. You can enable them by clicking below."));
579 return ($display);
580 }
582 /* Assign ACLs to smarty*/
583 foreach($this->attributes as $attr){
584 $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
585 }
587 /* Assign system types
588 */
589 $smarty->assign("SystemTypeKeys", array_flip($this->handle->getSystemTypes()));
590 $smarty->assign("SystemTypes", $this->handle->getSystemTypes());
591 $smarty->assign("type", $this->type);
593 /* Assign os types
594 */
595 $smarty->assign("OSKeys", array_flip($this->handle->getOSTypes()));
596 $smarty->assign("OSs", $this->handle->getOSTypes());
597 $smarty->assign("os", $this->os);
599 /* Dispaly installed devices */
600 $smarty->assign("InstalledDevices" ,$this->getDevices());
601 $smarty->assign("InstalledDeviceKeys" ,array_flip($this->getDevices()));
603 /* Append manufacturers
604 */
605 $smarty->assign("ManufacturerKeys", array_flip($this->handle->getEnterprises()));
606 $smarty->assign("Manufacturers", $this->handle->getEnterprises());
607 $smarty->assign("FK_glpi_enterprise", $this->FK_glpi_enterprise);
609 /* Assign used Attachments
610 */
612 $divlist = new divSelectBox("glpiAttachmentsList");
613 $divlist-> SetHeight(130);
614 $atts = $this->getUsedAttachments(true);
615 $downlink = "<a href='get_attachment.php?id=%s' target='_blank'>%s</a>";
616 $del_link = "<input type='image' src='images/edittrash.png' name='delAttachment_%s'>";
617 foreach($atts as $id => $attachment){
618 $divlist->AddEntry
619 (
620 array(
621 array("string"=>$attachment['name']),
622 array("string"=>$attachment['mime']),
623 array("string"=>sprintf($downlink,$id,$attachment['filename'])),
624 array("string"=>sprintf($del_link,$attachment['ID']),"attach"=>"style='border-right:0px;'"),
625 )
626 );
627 }
629 $smarty->assign("AttachmentsDiv" ,$divlist->DrawList());
630 /* Handle contact person
631 Assign name ... to smarty, if set
632 */
633 if(isset($users[$this->contact_num])){
634 $ldap->cat($users[$this->contact_num], array('givenName', 'sn', 'uid'));
635 $tr = $ldap->fetch();
636 $str = "";
637 if(isset($tr['givenName'][0])){ $str .= $tr['givenName'][0]." "; }
638 if(isset($tr['sn'][0])) { $str .= $tr['sn'][0]." "; }
639 if(isset($tr['uid'][0])){ $str .= "[".$tr['uid'][0]."]"; }
640 $smarty->assign("contact_num", $str);
641 }else{
642 $smarty->assign("contact_num", _("N/A"));
643 }
645 /* Handle tech person
646 Assign name ... to smarty, if set
647 */
648 if(isset($users[$this->tech_num])){
649 $tr = $ldap->cat($users[$this->tech_num], array('givenName', 'sn', 'uid'));
650 $tr = $ldap->fetch();
651 $str = "";
652 if(isset($tr['givenName'][0])){ $str .= $tr['givenName'][0]." "; }
653 if(isset($tr['sn'][0])) { $str .= $tr['sn'][0]." "; }
654 if(isset($tr['uid'][0])){ $str .= "[".$tr['uid'][0]."]"; }
655 $smarty->assign("tech_num", $str);
656 }else{
657 $smarty->assign("tech_num", _("N/A"));
658 }
659 $smarty->assign("comments", $this->comments);
661 $display.= $smarty->fetch(get_template_path('glpi.tpl', TRUE));
662 return($display);
663 }
665 function remove_from_parent()
666 {
667 if(!$this->initialy_was_account){
668 return;
669 }
670 if(function_exists("mysql_pconnect")){
671 $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
672 if($this->initialy_was_account){
673 $this->handle->removeComputerInformations($this->dn);
674 }
675 }else{
676 print_red(_("Can't remove glpi account, while mysql extension is missing."));
677 }
679 }
681 function getDevices(){
682 $ret = array();
683 foreach($this->usedDevices as $type => $entries){
684 foreach($entries as $ent){
685 if(isset($ent['designation'])){
686 $ret[] = $ent['designation']." [".$type."]";
687 }else{
688 $ret[] = $ent['name']." [".$type."]";
689 }
690 }
691 }
692 return($ret);
693 }
696 /* Save data to object */
697 function save_object()
698 {
699 if(!isset($_POST['glpi_tpl_posted'])) {
700 return ;
701 }
702 plugin::save_object();
703 }
706 /* Check supplied data */
707 function check()
708 {
709 /* Call common method to give check the hook */
710 $message= plugin::check();
712 // if($this->TechnicalResponsible == ""){
713 // $message[] = _("Please select a technical responsible person for this entry.");
714 // }
716 return ($message);
717 }
719 /* Save to LDAP */
720 function save()
721 {
722 if($this->is_account){
723 $attrs = array();
724 $this->date_mod = date("Y-m-d H:i:s");
725 foreach($this->attributes as $attr){
726 $attrs[$attr] = $this->$attr;
727 }
728 $attrs['name'] = $this->dn;
729 unset($attrs['ID']);
730 $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
732 /* check if we have to update, add */
733 if($this->initialy_was_account&&$this->is_account){
734 $this->handle->updateComputerInformations($attrs,$this->orig_dn);
735 }elseif($this->is_account){
736 $this->handle->addComputerInformations($attrs,$this->dn);
737 }
738 $tmp = $this->handle->getComputerInformations($this->dn);
739 $this->handle->addDevicesToComputer($this->usedDevices,$tmp[0]['ID']);
740 }
741 }
743 /* Return used attachments */
744 function getUsedAttachments($divlist = false)
745 {
746 $atts =$this->handle->getAttachments();
747 $ret = array();
748 foreach($atts as $entry){
749 if(in_array($entry['ID'],$this->usedAttachments)){
750 if($divlist){
751 $ret[$entry['ID']] = $entry;
752 }else{
753 $cm ="";
754 if(isset($entry['comment'])){
755 $cm=" [".$entry['comment']."]";
756 }
757 if(isset($entry['mime'])){
758 $cm.=" -".$entry['mime']."";
759 }
761 $ret[$entry['ID']]= $entry['name'].$cm;
762 }
763 }
764 }
765 return($ret);
766 }
769 }
771 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
772 ?>