diff --git a/plugins/admin/systems/class_glpiPrinterAccount.inc b/plugins/admin/systems/class_glpiPrinterAccount.inc
index 1e8aac795b74059abace4b9e453b721857953ac4..2fbffd147c576f7b3b8ebf3862c14208c693cae2 100644 (file)
var $comments = ""; // Comment
- var $type = 0; // System type id
+ var $type = 0; // printer type id
var $serial = "";
var $otherserial = "";
var $ramSize = 0;
var $contact = ""; // Empty
var $deleted = "N"; // Deleted entries should have this set to Y
+ var $editManufacturer = false;
+
/* Not necessary, cause we use mysql databse */
var $objectclasses= array("whatever");
var $usedDevices = array(); // Which devices are currently selected
var $usedAttachments = array(); // Used Attachments
+ var $usedCartridges = array(); // Used Cartridges
/* Contructor
Sets default values and checks if we already have an existing glpi account
plugin::plugin ($config, $dn);
$this->ui= get_userinfo();
+ $this->is_account = false;
+
/* Abort class construction, if no db is defined */
if(!isset($this->config->data['SERVERS']['GLPI'])){
return;
foreach($atts as $attachment){
$this->usedAttachments[$attachment['FK_doc']]=$attachment['FK_doc'];
}
+
+ $cart= $this->handle->getUsedCartridges($tmp[0]['ID']);
+ foreach($cart as $key => $cartridge){
+ $this->usedCartridges[$key]=$cartridge;
+ $this->usedCartridges[$key]['status']="exists";
+ }
+
+
}else{
$this->is_account = false;
}
$smarty= get_smarty();
$display= "";
+ $smarty->assign("CartridgesACL",chkacl($this->acl,"Cartridges"));
+
/* Assign smarty defaults
To avoid undefined indexes, if there is an error with the glpi db
*/
- foreach(array("PrinterTypeKeys","PrinterTypes") as $attr){
+ foreach(array("PrinterTypeKeys","PrinterTypes","ManufacturerKeys","Manufacturers","Attachments","AttachmentKeys") as $attr){
$smarty->assign($attr,array());
$smarty->assign($attr."ACL"," disabled ");
}
- foreach(array("type") as $attr){
+ foreach(array("type","FK_glpi_enterprise","tech_num","contact_num","comments","flags_serial","flags_par","flags_usb") as $attr){
$smarty->assign($attr,"");
$smarty->assign($attr."ACL"," disabled ");
}
if(isset($_POST['edit_manufacturer'])){
$this->cur_dialog = new glpiManufacturer($this->config,$this->dn);
$this->dialog = true;
+ $this->editManufacturer =true;
}
/* Close manufacturer editing dialog
*/
- if(isset($_POST['close_edit_manufacturer'])){
+ if((isset($_POST['close_edit_manufacturer']))&&($this->editManufacturer)){
$this->dialog = false;
$this->cur_dialog = false;
+ $this->editManufacturer=false;
}
*/
if(isset($_POST['SelectContactPerson'])){
$this->addUser = "contact";
- $this->cur_dialog= new glpiSelectUser($this->config,$this->dn);
+ $this->cur_dialog= new glpiSelectUser($this->config,$this->dn,"user_tech_num");
}
/* Selecte technical responsible person
*/
if(isset($_POST['SelectTechPerson'])){
$this->addUser ="tech";
- $this->cur_dialog= new glpiSelectUser($this->config,$this->dn);
+ $this->cur_dialog= new glpiSelectUser($this->config,$this->dn,"user_tech_num");
}
/* Abort user selection
*/
+ $smarty->assign("AbortSelectUser","SelectUserCancel");
if(isset($_POST['SelectUserCancel'])){
$this->dialog = false;
$this->addUser ="";
}
}
+ /* ##########################################################################
+ * Printer Cartridge handling
+ */
+
+ /* Abort cartridge select dialog
+ */
+ if(isset($_POST['SelectCartridgeCancel'])){
+ $this->cur_dialog = false;
+ $this->edit_type = false;
+ }
+
+ /* Get selected cartridges and add them to our list
+ */
+ if(isset($_POST['SelectCartridgeSave'])){
+ $this->cur_dialog->save_object();
+ $carts = $this->cur_dialog->save();
+ foreach($carts as $cart){
+ $cart['status'] = "new";
+ $this->usedCartridges[] = $cart;
+ }
+ $this->cur_dialog = false;
+ $this->edit_type = false;
+ }
+
+ /* Remove cartridge
+ */
+ if((isset($_POST['RemoveCartridge']))&&(isset($_POST['Cartridges']))){
+
+ foreach($_POST['Cartridges'] as $cartID){
+
+ if(isset($this->usedCartridges[$cartID])){
+ if($this->usedCartridges[$cartID]['status'] == "exists"){
+ $this->usedCartridges[$cartID]['status'] = "deleted";
+ }else{
+ unset($this->usedCartridges[$cartID]);
+ }
+ }
+ }
+ }
+
+ /* Open Attachment pool to add/edit Attachments
+ */
+ if(isset($_POST['AddCartridge'])){
+ $this->cur_dialog = new glpiPrinterCartridges($this->config,$this->dn,$this->type);
+ $this->dialog = true;
+ }
+
+
/* ##########################################################################
* Draw Dialogs
*/
$smarty->assign("Attachments", $this->getUsedAttachments());
$smarty->assign("AttachmentKeys", array_flip($this->getUsedAttachments()));
+ /* Assign Cartridges
+ */
+ $smarty->assign("Cartridges", $this->getUsedCartridges());
+ $smarty->assign("CartridgeKeys", $this->getUsedCartridges(true));
/* ##########################################################################
* Assign contact and technical responsible person
$smarty->assign("tech_num", _("N/A"));
}
+ /* If theres a cartridge selected, you can't change the printer type.
+ */
+ $disp = true;
+
+ foreach($this->usedCartridges as $cart){
+ if($cart['status'] != "deleted"){
+ $disp = false;
+ }
+ }
+ if($disp==false){
+ $smarty->assign("typeACL","disabled");
+ }
+
$display.= $smarty->fetch(get_template_path('glpiPrinter.tpl', TRUE));
return($display);
}
/* Save data to object */
function save_object()
{
- plugin::save_object();
- foreach($this->attributes as $attrs){
- if(isset($_POST[$attrs])){
- $this->$attrs = $_POST[$attrs];
+ if(isset($_POST['glpiPrinterFlagsPosted'])){
+ plugin::save_object();
+ foreach($this->attributes as $attrs){
+ if(isset($_POST[$attrs])){
+ $this->$attrs = $_POST[$attrs];
+ }
}
- }
- foreach(array("flags_serial","flags_par","flags_usb") as $checkboxes){
- if(isset($_POST[$checkboxes])){
- $this->$checkboxes = 1;
- }else{
- $this->$checkboxes = 0;
+ foreach(array("flags_serial","flags_par","flags_usb") as $checkboxes){
+ if(isset($_POST[$checkboxes])){
+ $this->$checkboxes = 1;
+ }else{
+ $this->$checkboxes = 0;
+ }
}
}
}
$tmp = $this->handle->getPrinterInformations($this->dn);
$this->handle->addAttachmentsToPrinter($this->usedAttachments,$tmp[0]['ID']);
+
+ foreach($this->usedCartridges as $cart){
+ if($cart['status'] == "deleted"){
+ $this->handle->removeCartridgeFromPrinter($cart['ID']);
+ }elseif($cart['status'] == "new"){
+ $this->handle->addCartridgeFromPrinter($tmp[0]['ID'],$cart['type_ID']);
+ }
+ }
}
}
}
return($ret);
}
-
+
+ function getUsedCartridges($flip = false)
+ {
+ $ret = array();
+ foreach($this->usedCartridges as $key => $value){
+ if($value['status'] == "deleted") continue;
+ if($flip){
+ $ret[$key] = $key;
+ }else{
+ $ret[$key] = $value['name']." [".$value['type_name']."] "._("since")." :".$value['date_use'];
+ }
+ }
+ return($ret);
+ }
}