From: hickert Date: Thu, 19 Jan 2006 10:39:14 +0000 (+0000) Subject: Added some glpi cartridge functionality, but not yet finished X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=ca4974fc566e467592f0f6d59fac2453d071fc21;p=gosa.git Added some glpi cartridge functionality, but not yet finished git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2526 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/plugins/admin/systems/class_glpiPrinterAccount.inc b/plugins/admin/systems/class_glpiPrinterAccount.inc index 624ba23a5..7c8681689 100644 --- a/plugins/admin/systems/class_glpiPrinterAccount.inc +++ b/plugins/admin/systems/class_glpiPrinterAccount.inc @@ -21,7 +21,7 @@ class glpiPrinterAccount extends plugin var $comments = ""; // Comment - var $type = 0; // System type id + var $type = 0; // printer type id var $serial = ""; var $otherserial = ""; var $ramSize = 0; @@ -59,7 +59,7 @@ class glpiPrinterAccount extends plugin 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 @@ -104,6 +104,14 @@ class glpiPrinterAccount extends plugin 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; } @@ -123,6 +131,8 @@ class glpiPrinterAccount extends plugin $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 */ @@ -373,6 +383,50 @@ class glpiPrinterAccount extends plugin } } + /* ########################################################################## + * 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']))){ + if(isset($this->usedCartridges[$_POST['Cartridges']])){ + if($this->usedCartridges[$_POST['Cartridges']]['status'] == "exists"){ + $this->usedCartridges[$_POST['Cartridges']]['status'] = "deleted"; + }else{ + unset($this->usedCartridges[$_POST['Cartridges']]); + } + } + } + + /* 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 */ @@ -433,6 +487,10 @@ class glpiPrinterAccount extends plugin $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 @@ -529,6 +587,14 @@ class glpiPrinterAccount extends plugin } $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']); + } + } } } @@ -553,7 +619,20 @@ class glpiPrinterAccount extends plugin } 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); + } } diff --git a/plugins/admin/systems/class_glpiPrinterCartridges.inc b/plugins/admin/systems/class_glpiPrinterCartridges.inc new file mode 100644 index 000000000..a6ff09895 --- /dev/null +++ b/plugins/admin/systems/class_glpiPrinterCartridges.inc @@ -0,0 +1,187 @@ + "Eins ist toll", "zwei" => "Zwei ist noch besser"); + + /* attribute list for save action */ + var $ignore_account = TRUE; + var $attributes = array(); + var $objectclasses = array("whatever"); + + var $parent = NULL; // Contains parent class, to access glpi db handle + var $usedCartridges = array(); // IDs of used cartridges for this printer + var $PrinterType = 0; // Specifies which cartridge types are available + + function glpiPrinterCartridges ($config, $dn= NULL,$type) + { + plugin::plugin ($config, $dn); + + /* Assign some basic settings */ + $this->ui = get_userinfo(); + if(!isset($_SESSION['glpiCartridgeRegex'])){ + $_SESSION['glpiCartridgeRegex'] = "*"; + } + + /* Only display cartridges for this type of printer */ + $this->PrinterType = $type; + } + + function execute() + { + /* Call parent execute */ + plugin::execute(); + $display =""; + $smarty = get_smarty(); + + /* Check poted vars and do the requested job, but only once */ + $only_once = true; + foreach($_POST as $name => $value){ + + /* We have to create a new cartridge */ + if(preg_match("/^newcartridge/",$name)&&($only_once)){ + echo "new Cartridge"; + + $only_once = false; + } + } + + /* Edit cartridge */ + if(isset($_GET['act'])&&$_GET['act']=="edit_cartridge"){ + print_a($this->parent->handle->getCartridgeTypeInformations($_GET['id'])); + echo "edit"; + } + + /* remove cartridge */ + if(isset($_GET['act'])&&$_GET['act']=="del_cartridge"){ + print_a($this->parent->handle->getCartridgeTypeInformations($_GET['id'])); + echo "remove"; + } + + /* Create divlist */ + $divlist = new divlist("glpi devices"); + $divlist->SetEntriesPerPage(0); + $divlist->SetHeader(array( + array("string" => " ", "attach" => "style='text-align:center;width:20px;'"), + array("string" => _("Cartridges"), "attach" => "style=''"), + array("string" => _("Action"), "attach" => "style='width:60px;border-right:0px;text-align:right;'" ))); + + /* Links for editing,adding.... */ + $edit = "%s"; + $editdel = ""._("Edit").""; + $editdel.= ""._("Delete").""; + + /* Checkbox for selection of some cartridges */ + $useCartridge = ""; + + /* Add cartridges */ + $cart = $this->getCartridgeTypes(); + foreach($cart as $key=>$cartr){ + + /* check if this cartridge is selected */ + $chk = ""; + if(isset($this->usedCartridges[$key])){ + $chk = " checked "; + } + + /* Add fields */ + $field1 = array("string" => preg_replace("/%s/",($key),preg_replace("/%CHECKED%/",$chk,$useCartridge)), "attach" => "style='text-align:center;width:20px;'"); + $field2 = array("string" => sprintf($edit,($key),$cartr['cartridgeName']." [".$cartr['cartridgeTypeName']."]"), "attach" => "style=''"); + $field3 = array("string" => sprintf($editdel,($key),($key)), + "attach" => "style='width:60px;border-right:0px;text-align:right;'"); + $divlist->AddEntry(array($field1,$field2,$field3)); + + } + + /* Create list header */ + $listhead = "
". + "  ". + "
"; + + /* Tell smarty some vars */ + $filter= $_SESSION['glpiCartridgeRegex']; + $smarty->assign("devicehead", $listhead); + $smarty->assign("devices", $divlist->DrawList()); + $smarty->assign("search_image", get_template_path('images/search.png')); + $smarty->assign("searchu_image", get_template_path('images/search_user.png')); + $smarty->assign("tree_image", get_template_path('images/tree.png')); + $smarty->assign("infoimage", get_template_path('images/info.png')); + $smarty->assign("launchimage", get_template_path('images/launch.png')); + $smarty->assign("apply", apply_filter()); + $smarty->assign("alphabet", generate_alphabet()); + $smarty->assign("cartridge_regex", $filter['device_regex']); + + $display.= $smarty->fetch(get_template_path('glpiPrinterCartridges.tpl', TRUE)); + return($display); + } + + /* Save device to glpi database + * If this is a new device, create a new entry, else update this entry + */ + function save() + { + $carts = $this->getCartridgeTypes(); + $ret = array(); + foreach($this->usedCartridges as $key){ + $tmp =array(); + $tmp['date_use'] = date("Y-m-d"); + $tmp['ID'] = -1; + $tmp['type_ID'] = $carts[$key]['cartridgeID']; + $tmp['name'] = $carts[$key]['cartridgeName']; + $tmp['FK_glpi_printers']= -1; + $tmp['type_name'] = $carts[$key]['cartridgeTypeName']; + $ret[$key] = $tmp; + } + return($ret); + } + + /* this only gets all already defined devices */ + function reload() + { + $this->devices = $this->parent->handle->getDevices(); + ksort($this->devices); + } + + /* This funtions saves all POST variables. + The variable must be in the array $this->EditEntry + */ + function save_object() + { + /* Checkbox handling + * Check which checkbox is selected + */ + foreach($_POST as $name => $value){ + if(preg_match("/wasOnPage/",$name)){ + $id = preg_replace("/wasOnPage_/","",$name); + if(isset($_POST['useCartridge_'.$id])){ + $this->usedCartridges[$id]=$id; + }else{ + unset($this->usedCartridges[$id]); + } + } + } + } + + /* This function cehck all created devices if you wan't to create device specific check + use >>if($attr['device_type']=="moboard")<< to create a device type depending check + */ + function check($attr) + { + $message = array(); + return($message); + } + + /* Return cartriges for our divlist */ + function getCartridgeTypes() + { + $ret = array(); + $ret = $this->parent->handle->getAvailableCartridgeTypes($this->PrinterType); + return($ret); + } +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/plugins/admin/systems/glpiPrinter.tpl b/plugins/admin/systems/glpiPrinter.tpl index 03a758cf3..d41003fee 100644 --- a/plugins/admin/systems/glpiPrinter.tpl +++ b/plugins/admin/systems/glpiPrinter.tpl @@ -47,7 +47,18 @@ +

 

+

{t}Information{/t}

+ + + + +
+ +
+ +

{t}Supported interfaces{/t}

@@ -76,29 +87,29 @@
- - -

{t}Information{/t}

- +

 

+

{t}Attachments{/t}

+
-
- {t}Comments{/t} - - + + +

 

-

{t}Attachments{/t}

+

{t}Installed cartridges{/t}

- + {html_options values=$CartridgeKeys output=$Cartridges} - - + +
diff --git a/plugins/admin/systems/glpiPrinterCartridges.tpl b/plugins/admin/systems/glpiPrinterCartridges.tpl new file mode 100644 index 000000000..de7110f48 --- /dev/null +++ b/plugins/admin/systems/glpiPrinterCartridges.tpl @@ -0,0 +1,54 @@ + + + + + +
+
+

+ {t}List of available cartridge type for this type of printer{/t} +

+
+
+ {$devicehead} +
+
+
+ {$devices} + +
+
+
+

[i]{t}Information{/t}

+
+
+

+ {t}This dialog allows you to create new types of cartridges, and select one or more types for your printer. Cartridge types depends on the printer type you have selected. For each selected cartridge type there will be a new cartridge created, this allows you to select the same cartridge type for more then one printer.{/t} +

+
+
+
+

[F]{t}Filters{/t}

+
+
+ + {$alphabet} +
+ + + + + +
+ +
+ {$apply} +
+
+ + +

 

+
+ + +