Code

Added branches container for old stuff
[gosa.git] / gosa-plugins / glpi / admin / systems / services / glpi / class_glpiPrinterAccount.inc
1 <?php
3 class glpiPrinterAccount extends plugin
4 {
5   /* attribute list for save action */
6   var $ignore_account= FALSE;
7   var $attributes= array("ID","name","contact","ramSize","flags_serial","flags_par","flags_usb",
8       "tech_num","comments","date_mod","location","domain","network","contact_num","serial","otherserial",
9       "type","is_template","FK_glpi_enterprise","deleted");
11   var $ID                 ;       // Is set if this entry is edited 
12   var $name               = "";    // This should be the dn of this entry 
13   var $FK_glpi_enterprise = 0;     // Manufacturer id
14   var $tech_num           = "";    // Technical responsible person
15   var $contact_num        = "";    // Contact person
16   
17   var $comments           = "";    // Comment
18   
19   var $type               = 0;     // printer type id
20   var $serial             = "";   
21   var $otherserial        = "";  
22   var $ramSize            = 0;
23   var $flags_serial       = false;
24   var $flags_par          = false;
25   var $flags_usb          = false;
27   var $date_mod           = "";    // Modification timestamp
28   
29   var $location           = 0;     // Not used yet
30   var $domain             = 0;     // ? Set to 0
31   var $network            = 0;     // ? Set to 0 
33   var $is_template        = 0;     // Used as template ?
34   var $contact            = "";    // Empty
35   var $deleted            = "N";   // Deleted entries should have this set to Y
37   var $rename             = false;
38   var $select_type        ;
40   var $editManufacturer   = false;
42   /* Not necessary, cause we use mysql databse */
43   var $objectclasses= array("whatever");
45   /* Used to remember if this was an account (simply: is this an edited entry) */
46   var $initially_was_account = false;
48   /* Remember current dialog */
49   var $edit_type            = false;
50   var $edit_os              = false;
52   var $data;
53   var $handle = NULL;               // Glpi class handle used to query database
55   var $cur_dialog = NULL;           // This contains the sub dialog handle
57   var $orig_dn;                     // To check if dn, has changed 
58   var $ui;                          // Some GOsa specific user informations 
59   
60   var $usedDevices      = array();  // Which devices are currently selected 
61   var $usedAttachments  = array();  // Used Attachments 
62   var $usedCartridges   = array();  // Used Cartridges
64   var $view_logged      = FALSE;
66   /* Contructor 
67      Sets default values and checks if we already have an existing glpi account
68    */
69   function glpiPrinterAccount (&$config, $dn= NULL, $parent= NULL)
70   {
71     plugin::plugin ($config, $dn, $parent);
72     $this->ui= get_userinfo();
74     $this->is_account = false;
76     /* Abort class construction, if no db is defined */
77     if(!isset($this->config->data['SERVERS']['GLPI'])){
78       return;
79     }
81     // Get informations about databse connection
82     $this->data = $this->config->data['SERVERS']['GLPI'];
84     // Abort if mysql extension is missing 
85     if(!is_callable("mysql_connect")){
86       return;
87     }
89     // Create handle of glpi class, and check if database connection is established 
90     $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
92     if(!$this->handle->is_connected){
93       return;
94     } 
96     // If this dn is already used in database, then get all informations for this entry 
97     if($this->handle->is_printer_account($this->dn)){
98       $this->is_account = true;
99       $tmp = ($this->handle->getPrinterInformations($this->dn));
101       foreach(array("tech_num","FK_glpi_enterprise","type","comments","contact_num","flags_serial","flags_par","flags_usb","ramSize") as $attr){
102         $this->$attr = $tmp[0][$attr];
103       }
104       
105       $atts = $this->handle->getAssignPrinterAttachments($tmp[0]['ID']);
106       foreach($atts as $attachment){
107         $this->usedAttachments[$attachment['FK_doc']]=$attachment['FK_doc']; 
108       }
110       $cart= $this->handle->getUsedCartridges($tmp[0]['ID']);
111       foreach($cart as $key => $cartridge){
112         $this->usedCartridges[$key]=$cartridge; 
113         $this->usedCartridges[$key]['status']="exists"; 
114       }
117     }else{
118       $this->is_account = false;
119     }
121     /* set defaults */
122     $this->name                 = $this->dn;
123     $this->orig_dn              = $this->dn;
124     $this->initially_was_account = $this->is_account;
125   }
127   function execute()
128   {
129     /* Call parent execute */
130     plugin::execute();
132     if($this->is_account && !$this->view_logged){
133       $this->view_logged = TRUE;
134       new log("view","printer/".get_class($this),$this->dn);
135     }
137     /* Fill templating stuff */
138     $smarty= get_smarty();
139     $display= "";
141     $smarty->assign("CartridgesACL",$this->getacl("Cartridges"));
143     /*  Assign smarty defaults 
144         To avoid undefined indexes, if there is an error with the glpi db
145      */ 
146     foreach(array("PrinterTypeKeys","PrinterTypes","ManufacturerKeys","Manufacturers",
147                   "Attachments","AttachmentKeys","CartridgeKeys","Cartridges") as $attr){
148       $smarty->assign($attr,array());
149     }
150     foreach(array("type","FK_glpi_enterprise","tech_num","contact_num","comments","flags_serial","flags_par","flags_usb","AttachmentsDiv") as $attr){
151       $smarty->assign($attr,"");
152     }
154     /* Assign acls */
155     $tmp = $this->plInfo();
156     foreach($tmp['plProvidedAcls'] as $name => $translation){
157       $smarty->assign($name."ACL",$this->getacl($name));
158     }
160     /* Check if there is a glpi database server defined 
161       */
162     if(!isset($this->config->data['SERVERS']['GLPI'])){
163       print_red(_("There is no server with valid glpi database service."));
164       return($smarty->fetch(get_template_path('glpiPrinter.tpl',TRUE,dirname(__FILE__))));
165     }
167     $this->data = $this->config->data['SERVERS']['GLPI'];
169     /* Check if we can call mysql_connect 
170        If we can't, there is no the mysql-php extension
171      */
172     if(!is_callable("mysql_connect")){
173       print_red(_("Can't connect to glpi database, the php-mysql extension is missing."));
174       return($smarty->fetch(get_template_path('glpiPrinter.tpl',TRUE,dirname(__FILE__))));
175     }
177     $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
179     /*  If handle == false, abort
180         Seems that the server, username and or password is wrong
181      */
182     if(!$this->handle->is_connected){
183       print_red(_("Can't connect to glpi database, check configuration twice."));
184       return($smarty->fetch(get_template_path('glpiPrinter.tpl',TRUE,dirname(__FILE__))));
185     } 
187     /* Download requested of attachment requested.
188      */
189     if(isset($_GET['get_attachment'])){
190       $atts = $this->handle->getAttachments();
191       if(isset($atts[$_GET['get_attachment']])){
192         $att = $atts[$_GET['get_attachment']];
193         $filename = CONFIG_DIR."/glpi/".$att['filename'];
194         if(file_exists($filename) && is_readable($filename)){
195           $str = file_get_contents($filename);
196           send_binary_content($str,$att['filename']);
197         }else{
198           print_red(_("Download of attachment failed. Attachment was not found on server."));
199         }
200       }else{
201         print_red(_("Download of attachment failed. Not a valid attachment id."));
202       }
203     }
206     /*  All checks are ok
207         Lets handle Posts, templates etc below ...
208      */
209     
210     $users = $this->handle->getUsers();
211     $ldap= $this->config->get_ldap_link();
213     
214     /*  ##########################################################################
215      *  Some tab management   
216      */
218     /* Do we need to flip is_account state? */
219     if(isset($_POST['modify_state'])){
220       if($this->is_account && $this->acl_is_removeable()){
221         $this->is_account= FALSE;
222       }elseif(!$this->is_account && $this->acl_is_createable()){
223         $this->is_account= TRUE;
224       }
225     }
227     /* Show tab dialog headers */
228     if ($this->is_account){
229       $display= $this->show_disable_header(_("Remove inventory"),
230           _("This server has inventory features enabled. You can disable them by clicking below."));
231     } else {
232       $display= $this->show_enable_header(_("Add inventory"),
233           _("This server has inventory features disabled. You can enable them by clicking below."));
234       return ($display);
235     }
237     
238     /*  ##########################################################################
239      *  Printer type management 
240      *  Dialog 
241      */
243     /* Rename was requested */
244     if(isset($_POST['Rename_PType_OK']) && $this->acl_is_writeable("type")){
245       $tmp = $this->handle->getPrinterTypes();
246       $allok = true;
247       foreach($tmp as $id => $name){
248         if(trim($name) == trim($_POST['string'])){
249           $allok = false;
250         }
251       }
252       if($allok){
253         $this->handle->updatePrinterType($_POST['string'],$this->select_type);
254         $this->rename = false;
255       }else{
256         print_red(sprintf(_("Can't rename given printer type to '%s', because this type name already exists."),$_POST['string']));
257       }
258     }
260     /* abort rename 
261      */
262     if(isset($_POST['Rename_Cancel'])){
263       $this->rename = false;
264     }
266     /* Printer type management
267      */
268     if(isset($_POST['edit_type']) && $this->acl_is_writeable("type")){
269       $this->dialog = true;
270       $this->edit_type=true;
271     }
273     /* This closes the printer type editing dialog
274      */
275     if(isset($_POST['close_edit_type'])){
276       $this->edit_type=false;
277       $this->dialog = false;
278     }
280     /* This appends a new printer to our sytem types
281      */
282     if((isset($_POST['add_type']))&&(!empty($_POST['type_string'])) && $this->acl_is_writeable("type")){
283     
284       $tmp = $this->handle->getPrinterTypes();
285       $allok = true;
286       foreach($tmp as $id => $name){
287         if(trim($name) == trim($_POST['type_string'])){
288           $allok = false;
289         }
290       }
291       if($allok){
292         $this->handle->addPrinterType($_POST['type_string']);  
293       }else{
294         print_red(sprintf(_("Can't rename given printer type to '%s', because this type name already exists."),$_POST['type_string']));
295       }
296     }
298     /* Remove selected type from our printer types list
299      */
300     if((isset($_POST['del_type']))&&(!empty($_POST['select_type'])) && $this->acl_is_writeable("type")){
301       $tmp = $this->handle->is_printerTypeUsed($_POST['select_type']);
302       if(count($tmp)){
303         $str = "";
304         foreach($tmp as $id => $name){
305           $str .= $name.", ";
306         }
307         $str = preg_replace("/, $/","",$str); 
308         print_red(sprintf(_("Can't delete printer type, it is still in use by '%s'."),$str));
309       }else{
310         $this->handle->removePrinterType($_POST['select_type']);  
311       }
312     }
314     /* Rename selected printer type to given string
315      */
316     if((isset($_POST['rename_type']))&&(!empty($_POST['select_type']))||($this->rename) && $this->acl_is_writeable("type")){
317       $this->rename = true;
319       $smarty->assign("Method","rename");
321       $tmp = $this->handle->getPrinterTypes();
323       if(isset($_POST['select_type'])){
324         $this->select_type = $_POST['select_type'];
325       }  
326       $smarty->assign("string",$tmp[$this->select_type]);
327       if(isset($_POST['string'])){
328         $smarty->assign("string",$_POST['string']);
329       }
331       $display= $smarty->fetch(get_template_path('glpi_edit_printer_type.tpl',TRUE,dirname(__FILE__)));
332       return($display);
333     }  
335     /* Someone wants to edit the printer types ... 
336        So, lets open a new dialog which provides some buttons to edit the types
337      */
338     if($this->edit_type){
339       $smarty->assign("Method","edit");
340       $smarty->assign("PrinterTypes",            $this->handle->getPrinterTypes());
341       $smarty->assign("PrinterTypeKeys",         array_flip($this->handle->getPrinterTypes()));
342       $display= $smarty->fetch(get_template_path('glpi_edit_printer_type.tpl',TRUE,dirname(__FILE__)));
343       return($display);
344     }
347     /*  ##########################################################################
348      *  Edit manufacturers 
349      *  Dialog 
350      */
352     /* Open dialog which allows to edit the manufacturers
353      */
354     if(isset($_POST['edit_manufacturer']) && $this->acl_is_writeable("FK_glpi_enterprise")){
355       $this->cur_dialog = new glpiManufacturer($this->config,$this->dn);
356       $this->dialog = true;
357       $this->editManufacturer =true;
358     }
360     /* Close manufacturer editing dialog
361      */
362     if((isset($_POST['close_edit_manufacturer']))&&($this->editManufacturer)){
363       $this->dialog = false;
364       $this->cur_dialog = false;
365       $this->editManufacturer=false;
366     }
369     /*  ##########################################################################
370      *  Technical responsible person
371      *  Contact person 
372      *  Dialog 
373      */
375     /* Show dialog to select a new contact person
376      * Select a contact person
377      */
378     if(isset($_POST['SelectContactPerson']) && $this->acl_is_writeable("contact_num")){
379       $this->addUser = "contact";
380       $this->cur_dialog= new glpiSelectUser($this->config,$this->dn,"user_tech_num");
381     }
383     /* Selecte technical responsible person
384      */
385     if(isset($_POST['SelectTechPerson']) && $this->acl_is_writeable("tech_num")){
386       $this->addUser ="tech";
387       $this->cur_dialog= new glpiSelectUser($this->config,$this->dn,"user_tech_num");
388     }
390     /* Abort user selection
391      */
392     $smarty->assign("AbortSelectUser","SelectUserCancel");
393     if(isset($_POST['SelectUserCancel'])){
394       $this->dialog = false;
395       $this->addUser ="";
396       $this->cur_dialog = false;
397     }
399     /* Technical responsible/contact person selected */
400     if(isset($_GET['act'])&&($_GET['act']=="user_tech_num")){
402       /* Get posted id */
403       $id = base64_decode($_GET['id']);
405       /* Check if user is already created in glpi database */
406       if(!in_array($id,$users)){
408         /* If this user doesn't exists in glpi db, we must create him */
409         $ldap->cat($id, array('cn', 'mail', 'telephoneNumber'));
410         $atr = $ldap->fetch();
411         $tmp = array();
412         $use = array( "cn"              =>"name",
413             "mail"            =>"email",
414             "telephoneNumber" =>"phone");
416         /* Create array */
417         foreach($use as $gosa => $glpi){
418           if(isset($atr[$gosa])){
419             $tmp[$glpi]= $atr[$gosa][0];
420           }
421         }
423         /* Add this user */
424         $this->handle->addUser($tmp,$id);
425       }
427       /* Re-read users */
428       $users = ($this->handle->getUsers());
430       /* Get user */
431       $tmp = array_flip($users);
432       $id=$tmp[$id];
434       /* Use user id, close dialog */
435       if($this->addUser == "tech"){
436         $this->tech_num = $id;
437       }else{
438         $this->contact_num = $id;
439       }
440       $this->cur_dialog   = false;
441       $this->dialog= false;
442     }
445     /*  ##########################################################################
446      *  Handle attachments 
447      */
448     
449     /* Attachment pool was closed with use
450      */
451     if(isset($_POST['UseAttachment']) && $this->acl_is_writeable("Attachments")){
452       if(count($this->cur_dialog->check())){
453         foreach($this->cur_dialog->check() as $msg){
454           print_red($msg);
455         }
456       }else{
457         $this->cur_dialog->save_object();
458         $this->usedAttachments = $this->cur_dialog->save();
459         $this->cur_dialog = false;
460         $this->edit_type = false; 
461       }
462     }
463    
464     /* Attachment pool was closed with abort
465      */ 
466     if(isset($_POST['AbortAttachment'])){
467       $this->cur_dialog = false;
468       $this->edit_type = false; 
469     }
471     /* Open Attachment pool to add/edit Attachments
472      */
473     if(isset($_POST['AddAttachment']) && $this->acl_is_writeable("Attachments")){
474       $this->cur_dialog = new glpiAttachmentPool($this->config,$this->dn,$this->usedAttachments);
475       $this->dialog = true;
476     }
477     
478     /* Remove Attachment from this tab 
479      */
480     $once = true;
481     foreach($_POST as $name => $value){
482       if((preg_match("/^delAttachment_/",$name))&&($once) && $this->acl_is_writeable("Attachments")){
483         $once= false;
484         $name = preg_replace("/^delAttachment_/","",$name);
485         $entry = preg_replace("/_.*$/","",$name);
486         if(isset($this->usedAttachments[$entry])){
487           unset($this->usedAttachments[$entry]);
488         }
489       }
490     }
491     if((isset($_POST['RemoveAttachment']))&&(isset($_POST['Attachments'])) && $this->acl_is_writeable("Attachments")){
492       if(isset($this->usedAttachments[$_POST['Attachments']])){
493         unset($this->usedAttachments[$_POST['Attachments']]);
494       }
495     }
497     /*  ##########################################################################
498      *  Printer Cartridge handling 
499      */
501     /* Abort cartridge select dialog
502      */
503     if(isset($_POST['SelectCartridgeCancel'])){
504       $this->cur_dialog = false;
505       $this->edit_type = false; 
506     }
508     /* Get selected cartridges and add them to our list 
509      */ 
510     if(isset($_POST['SelectCartridgeSave'])){
511       $this->cur_dialog->save_object();
512       $carts = $this->cur_dialog->save();
513       foreach($carts as $cart){
514         $cart['status'] = "new";
515         $this->usedCartridges[] = $cart;
516       }
517       $this->cur_dialog = false;
518       $this->edit_type = false; 
519     }
521     /* Remove cartridge  
522      */
523     if((isset($_POST['RemoveCartridge']))&&(isset($_POST['Cartridges'])) && $this->acl_is_writeable("ManageCartridges")){
525       foreach($_POST['Cartridges'] as $cartID){
527         if(isset($this->usedCartridges[$cartID])){
528           if($this->usedCartridges[$cartID]['status'] == "exists"){
529             $this->usedCartridges[$cartID]['status'] = "deleted";
530           }else{
531             unset($this->usedCartridges[$cartID]);
532           }
533         }
534       }
535     }
537     /* Open Attachment pool to add/edit Attachments
538      */
539     if(isset($_POST['AddCartridge']) && $this->acl_is_writeable("ManageCartridges")){
540       $this->cur_dialog = new glpiPrinterCartridges($this->config,$this->dn,$this->type);
541       $this->dialog = true;
542     }
545     /*  ##########################################################################
546      *  Draw Dialogs
547      */
548     /* if( cur_dialog != false || cur_dialog != NULL) 
549      * There is a dialog which wants to be displayed 
550      */
551     if($this->cur_dialog && is_object($this->cur_dialog)){
552       $this->cur_dialog->save_object();
553       $this->dialog=true;
554       $this->cur_dialog->parent = &$this;
555       return($this->cur_dialog->execute());
556     }else{
557       $this->dialog= false;
558     }
561     /*  ##########################################################################
562      *  Assign listbox / checkbox .... values to smarty  
563      */
564     /* Assign smarty defaults */ 
565     foreach(array("PrinterTypes","PrinterTypeKeys","Manufacturers","TechnicalResponsibles","Attachments","Cartridges") as $attr){
566       $smarty->assign($attr,array());
567     }
569     /* Assign some vars to smarty 
570      */
571     foreach(array("type","FK_glpi_enterprise","tech_num","contact_num","flags_serial","flags_par","flags_usb") as $attr){
572       $smarty->assign($attr,"");
573     }
575     $smarty->assign("comments",               $this->comments);
576     $smarty->assign("flags_serial",            $this->flags_serial);
577     $smarty->assign("flags_par",               $this->flags_par);
578     $smarty->assign("flags_usb",               $this->flags_usb);
580     /* Assign system types 
581      */
582     $smarty->assign("PrinterTypes",           $this->handle->getPrinterTypes());
583     $smarty->assign("PrinterTypeKeys",        array_flip($this->handle->getPrinterTypes()));
584     $smarty->assign("type",                   $this->type);
586     /* Append manufacturers
587      */
588     $smarty->assign("ManufacturerKeys",       array_flip($this->handle->getEnterprises()));
589     $smarty->assign("Manufacturers",          $this->handle->getEnterprises());
590     $smarty->assign("FK_glpi_enterprise",     $this->FK_glpi_enterprise);
592     /* Assign used Attachments
593     */
595     $divlist = new divSelectBox("glpiAttachmentsList");
596     $divlist-> SetHeight(120);
597     $atts = $this->getUsedAttachments(true);
598     $downlink = "<a href='?plug=".$_GET['plug']."&get_attachment=%s'>%s</a>";
599     $del_link = "<input type='image' src='images/lists/trash.png' name='delAttachment_%s'>";
600     foreach($atts as $id => $attachment){
601       $divlist->AddEntry
602           (
603         array(
604             array("string"=>$attachment['name']),
605             array("string"=>$attachment['mime']),
606             array("string"=>sprintf($downlink,$id,$attachment['filename'])),
607             array("string"=>sprintf($del_link,$attachment['ID']),"attach"=>"style='border-right:0px;'"),
608              )
609           );
610     }
612     $smarty->assign("AttachmentsDiv"          ,$divlist->DrawList());
613     $smarty->assign("Attachments",            $this->getUsedAttachments());
614     $smarty->assign("AttachmentKeys",         array_flip($this->getUsedAttachments()));
616     /* Assign Cartridges 
617      */
618     $smarty->assign("Cartridges",            $this->getUsedCartridges());
619     $smarty->assign("CartridgeKeys",         $this->getUsedCartridges(true));
621     /*  ##########################################################################
622      *  Assign contact and technical responsible person 
623      */
624     if(isset($users[$this->contact_num])){
625       $ldap->cat($users[$this->contact_num], array('givenName', 'sn', 'uid'));
626       $tr = $ldap->fetch();
627       $str = "";
628       if(isset($tr['givenName'][0])){   $str .= $tr['givenName'][0]." ";      }
629       if(isset($tr['sn'][0])) {         $str .= $tr['sn'][0]." ";             }
630       if(isset($tr['uid'][0])){         $str .= "[".$tr['uid'][0]."]";        }
631       $smarty->assign("contact_num",               $str);
632     }else{
633       $smarty->assign("contact_num",               _("N/A"));
634     }
636     /* Handle tech person 
637        Assign name ... to smarty, if set
638      */ 
639     if(isset($users[$this->tech_num])){
640       $ldap->cat($users[$this->tech_num], array('givenName', 'sn', 'uid'));
641       $tr = $ldap->fetch();
642       $str = "";
643       if(isset($tr['givenName'][0])){   $str .= $tr['givenName'][0]." ";      }
644       if(isset($tr['sn'][0])) {         $str .= $tr['sn'][0]." ";             }
645       if(isset($tr['uid'][0])){         $str .= "[".$tr['uid'][0]."]";        }
646       $smarty->assign("tech_num",               $str);
647     }else{
648       $smarty->assign("tech_num",               _("N/A"));
649     }
651     /* If theres a cartridge selected, you can't change the printer type.
652      */ 
653     $disp = true;
655     foreach($this->usedCartridges as $cart){
656       if($cart['status'] != "deleted"){
657         $disp = false;
658       }
659     }
660     if($disp==false){
661       $smarty->assign("typeACL", $this->getacl("type",true));
662     }
664     $display.= $smarty->fetch(get_template_path('glpiPrinter.tpl',TRUE,dirname(__FILE__)));
665     return($display);
666   }
668   function remove_from_parent()
669   {
670     $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
671     if($this->initially_was_account){
672       $this->handle->removePrinterInformations($this->dn);
673       new log("remove","printer/".get_class($this),$this->dn); 
674     }
675   }
678   /* Save data to object */
679   function save_object()
680   {
681     if(isset($_POST['glpiPrinterFlagsPosted'])){
682       plugin::save_object();
683       foreach($this->attributes as $attrs){
684         if(isset($_POST[$attrs])){
685           $this->$attrs = $_POST[$attrs];
686         }
687       }
689       if(isset($_POST['FK_glpi_enterprise']) && $this->acl_is_writeable("FKglpienterprise")){
690         $this->FK_glpi_enterprise = $_POST['FK_glpi_enterprise'];
691       }
693       foreach(array("flags_serial","flags_par","flags_usb") as $checkboxes){
694         if($this->acl_is_writeable($checkboxes)){
695           if(isset($_POST[$checkboxes])){
696             $this->$checkboxes = 1;
697           }else{
698             $this->$checkboxes = 0;
699           }
700         }
701       }
702     }
704   }
707   /* Check supplied data */
708   function check()
709   {
710     /* Call common method to give check the hook */
711     $message= plugin::check();
713     //    if($this->TechnicalResponsible == ""){
714     //      $message[] = _("Please select a technical responsible person for this entry.");
715     //    }
717     return ($message);
718   }
720   /* Save to LDAP */
721   function save()
722   {
723     if($this->is_account){
724         $attrs = array();
725       $this->date_mod = date("Y-m-d H:i:s");
726       foreach($this->attributes as $attr){
727         $attrs[$attr] = $this->$attr;
728       }
729       $attrs['name'] = $this->dn;
730       unset($attrs['ID']);
731       $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
732       if($this->initially_was_account&&$this->is_account){
733         $this->handle->updatePrinterInformations($attrs,$this->dn);
734         new log("modify","printer/".get_class($this),$this->dn); 
735       }elseif($this->is_account){
736         $this->handle->addPrinterInformations($attrs,$this->dn);
737         new log("create","printer/".get_class($this),$this->dn); 
738       }
739       $tmp = $this->handle->getPrinterInformations($this->dn);
740       $this->handle->addAttachmentsToPrinter($this->usedAttachments,$tmp[0]['ID']);
742       foreach($this->usedCartridges as $cart){
743         if($cart['status'] == "deleted"){
744           $this->handle->removeCartridgeFromPrinter($cart['ID']);
745         }elseif($cart['status'] == "new"){
746           $this->handle->addCartridgeFromPrinter($tmp[0]['ID'],$cart['type_ID']);
747         }
748       }
749     }
750   }
752   /* Return used attachments */
753   function getUsedAttachments($divlist = false)
754   {
755     $atts =$this->handle->getAttachments();
756     $ret = array();
757     foreach($atts as $entry){
758       if(in_array($entry['ID'],$this->usedAttachments)){
759         if($divlist){
760           $ret[$entry['ID']] = $entry;
761         }else{
762           $cm ="";
763           if(isset($entry['comment'])){
764             $cm=" [".$entry['comment']."]";
765           }
766           if(isset($entry['mime'])){
767             $cm.=" -".$entry['mime']."";
768           }
770           $ret[$entry['ID']]= $entry['name'].$cm;
771         }
772       }
773     }
774     return($ret);
775   }
777   function getUsedCartridges($flip = false)
778   {
779     $ret = array();
780     foreach($this->usedCartridges as $key => $value){
781       if($value['status'] == "deleted") continue;
782       if($flip){
783         $ret[$key] = $key;    
784       }else{
785         $ret[$key] = $value['name']." [".$value['type_name']."] "._("since")." :".$value['date_use'];
786       }
787     }
788     return($ret);
789   }  
791      /* Return plugin informations for acl handling */
792   static function plInfo()
793   {
794     return (array(
795           "plShortName"   => _("Glpi"),
796           "plDescription" => _("Printer inventory extension"),
797           "plSelfModify"  => FALSE,
798           "plDepends"     => array(),
799           "plPriority"    => 10,
800           "plSection"     => array("administration"),
801           "plCategory"    => array("printer"),
803           "plProvidedAcls"=> array(
804             "flags_serial"         => _("Supports serial interface"),
805             "flags_par"            => _("Supports parallel interface"),
806             "flags_usb"            => _("Supports usb interface"),
807             "tech_num"             => _("Technical responsible"),
808             "comments"             => _("Comments"),
809             "location"             => _("Location"),
810             "contact_num"          => _("Contact person"),
811             "type"                 => _("Type"),
812             "FKglpienterprise"   => _("Manufacturer"),
814             "Attachments"          => _("Attachments"),
815         
816             "ManageCartridges"            => _("Cartridge settings"))
817           ));
818   }
820 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
821 ?>