summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5d730b2)
raw | patch | inline | side by side (parent: 5d730b2)
author | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 17 Jan 2006 09:39:07 +0000 (09:39 +0000) | ||
committer | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 17 Jan 2006 09:39:07 +0000 (09:39 +0000) |
Initially commit, not complete
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2497 594d385d-05f5-0310-b6e9-bd551577e9d8
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2497 594d385d-05f5-0310-b6e9-bd551577e9d8
plugins/admin/systems/class_glpiPrinterAccount.inc | [new file with mode: 0644] | patch | blob |
plugins/admin/systems/glpiPrinter.tpl | [new file with mode: 0644] | patch | blob |
plugins/admin/systems/glpi_edit_printer_type.tpl | [new file with mode: 0644] | patch | blob |
plugins/admin/systems/tabs_printers.inc | patch | blob | history |
diff --git a/plugins/admin/systems/class_glpiPrinterAccount.inc b/plugins/admin/systems/class_glpiPrinterAccount.inc
--- /dev/null
@@ -0,0 +1,556 @@
+<?php
+
+class glpiPrinterAccount extends plugin
+{
+ /* CLI vars */
+ var $cli_summary= "Manage server basic objects";
+ var $cli_description= "Some longer text\nfor help";
+ var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
+
+ /* attribute list for save action */
+ var $ignore_account= FALSE;
+ var $attributes= array("ID","name","contact","ramSize","flags_serial","flags_par","flags_usb",
+ "tech_num","comments","date_mod","location","domain","network","contact_num","serial","otherserial",
+ "type","is_template","FK_glpi_enterprise","deleted");
+
+ var $ID ; // Is set if this entry is edited
+ var $name = ""; // This should be the dn of this entry
+ var $FK_glpi_enterprise = 0; // Manufacturer id
+ var $tech_num = ""; // Technical responsible person
+ var $contact_num = ""; // Contact person
+
+ var $comments = ""; // Comment
+
+ var $type = 0; // System type id
+ var $serial = "";
+ var $otherserial = "";
+ var $ramSize = 0;
+ var $flags_serial = false;
+ var $flags_par = false;
+ var $flags_usb = false;
+
+ var $date_mod = ""; // Modification timestamp
+
+ var $location = 0; // Not used yet
+ var $domain = 0; // ? Set to 0
+ var $network = 0; // ? Set to 0
+
+ var $is_template = 0; // Used as template ?
+ var $contact = ""; // Empty
+ var $deleted = "N"; // Deleted entries should have this set to Y
+
+ /* Not necessary, cause we use mysql databse */
+ var $objectclasses= array("whatever");
+
+ /* Used to remember if this was an account (simply: is this an edited entry) */
+ var $initially_was_account = false;
+
+ /* Remember current dialog */
+ var $edit_type = false;
+ var $edit_os = false;
+
+ var $data;
+ var $handle = NULL; // Glpi class handle used to query database
+
+ var $cur_dialog = NULL; // This contains the sub dialog handle
+
+ var $orig_dn; // To check if dn, has changed
+ var $ui; // Some GOsa specific user informations
+
+ var $usedDevices = array(); // Which devices are currently selected
+ var $usedAttachments = array(); // Used Attachments
+
+ /* Contructor
+ Sets default values and checks if we already have an existing glpi account
+ */
+ function glpiPrinterAccount ($config, $dn= NULL)
+ {
+ plugin::plugin ($config, $dn);
+ $this->ui= get_userinfo();
+
+ /* Abort class construction, if no db is defined */
+ if(!isset($this->config->data['SERVERS']['GLPI'])){
+ return;
+ }
+
+ // Get informations about databse connection
+ $this->data = $this->config->data['SERVERS']['GLPI'];
+
+ // Abort if mysql extension is missing
+ if(!is_callable("mysql_connect")){
+ return;
+ }
+
+ // Create handle of glpi class, and check if database connection is established
+ $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
+
+ if(!$this->handle->is_connected){
+ return;
+ }
+
+ // If this dn is already used in database, then get all informations for this entry
+ if($this->handle->is_printer_account($this->dn)){
+ $this->is_account = true;
+ $tmp = ($this->handle->getPrinterInformations($this->dn));
+
+ foreach(array("tech_num","FK_glpi_enterprise","type","comments","contact_num","flags_serial","flags_par","flags_usb","ramSize") as $attr){
+ $this->$attr = $tmp[0][$attr];
+ }
+
+ $atts = $this->handle->getAssignPrinterAttachments($tmp[0]['ID']);
+ foreach($atts as $attachment){
+ $this->usedAttachments[$attachment['FK_doc']]=$attachment['FK_doc'];
+ }
+ }else{
+ $this->is_account = false;
+ }
+
+ /* set defaults */
+ $this->name = $this->dn;
+ $this->orig_dn = $this->dn;
+ $this->initially_was_account = $this->is_account;
+ }
+
+ function execute()
+ {
+ /* Call parent execute */
+ plugin::execute();
+
+ /* Fill templating stuff */
+ $smarty= get_smarty();
+ $display= "";
+
+ /* Assign smarty defaults
+ To avoid undefined indexes, if there is an error with the glpi db
+ */
+ foreach(array("PrinterTypeKeys","PrinterTypes") as $attr){
+ $smarty->assign($attr,array());
+ $smarty->assign($attr."ACL"," disabled ");
+ }
+ foreach(array("type") as $attr){
+ $smarty->assign($attr,"");
+ $smarty->assign($attr."ACL"," disabled ");
+ }
+
+ /* Check if there is a glpi database server defined
+ */
+ if(!isset($this->config->data['SERVERS']['GLPI'])){
+ print_red(_("There is no server with valid glpi database service."));
+ return($smarty->fetch(get_template_path('glpiPrinter.tpl', TRUE)));
+ }
+
+ $this->data = $this->config->data['SERVERS']['GLPI'];
+
+ /* Check if we can call mysql_connect
+ If we can't, there is no the mysql-php extension
+ */
+ if(!is_callable("mysql_connect")){
+ print_red(_("Can't connect to glpi database, the php-mysql extension is missing."));
+ return($smarty->fetch(get_template_path('glpiPrinter.tpl', TRUE)));
+ }
+
+ $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
+
+ /* If handle == false, abort
+ Seems that the server, username and or password is wrong
+ */
+ if(!$this->handle->is_connected){
+ print_red(_("Can't connect to glpi database, check configuration twice."));
+ return($smarty->fetch(get_template_path('glpiPrinter.tpl', TRUE)));
+ }
+
+ /* All checks are ok
+ Lets handle Posts, templates etc below ...
+ */
+
+ $users = $this->handle->getUsers();
+ $ldap= $this->config->get_ldap_link();
+
+
+ /* ##########################################################################
+ * Some tab management
+ */
+
+ /* Do we need to flip is_account state? */
+ if (isset($_POST['modify_state'])){
+ $this->is_account= !$this->is_account;
+ }
+
+ /* Show tab dialog headers */
+ if ($this->is_account){
+ $display= $this->show_header(_("Remove inventory service"),
+ _("This server has inventory features enabled. You can disable them by clicking below."));
+ } else {
+ $display= $this->show_header(_("Add inventory service"),
+ _("This server has inventory features disabled. You can enable them by clicking below."));
+ return ($display);
+ }
+
+
+ /* ##########################################################################
+ * Printer type management
+ * Dialog
+ */
+
+ /* Printer type management
+ */
+ if(isset($_POST['edit_type'])){
+ $this->dialog = true;
+ $this->edit_type=true;
+ }
+
+ /* This closes the printer type editing dialog
+ */
+ if(isset($_POST['close_edit_type'])){
+ $this->edit_type=false;
+ $this->dialog = false;
+ }
+
+ /* This appends a new printer to our sytem types
+ */
+ if((isset($_POST['add_type']))&&(!empty($_POST['type_string']))){
+ $this->handle->addPrinterType($_POST['type_string']);
+ }
+
+ /* Remove selected type from our printer types list
+ */
+ if((isset($_POST['del_type']))&&(!empty($_POST['select_type']))){
+ $this->handle->removePrinterType($_POST['select_type']);
+ }
+
+ /* Rename selected printer type to given string
+ */
+ if((isset($_POST['rename_type']))&&(!empty($_POST['select_type']))&&(!empty($_POST['type_string']))){
+ $this->handle->updatePrinterType($_POST['type_string'],$_POST['select_type']);
+ }
+
+ /* Someone wants to edit the printer types ...
+ So, lets open a new dialog which provides some buttons to edit the types
+ */
+ if($this->edit_type){
+ $smarty->assign("PrinterTypes", $this->handle->getPrinterTypes());
+ $smarty->assign("PrinterTypeKeys", array_flip($this->handle->getPrinterTypes()));
+ $display= $smarty->fetch(get_template_path('glpi_edit_printer_type.tpl', TRUE));
+ return($display);
+ }
+
+
+ /* ##########################################################################
+ * Edit manufacturers
+ * Dialog
+ */
+
+ /* Open dialog which allows to edit the manufacturers
+ */
+ if(isset($_POST['edit_manufacturer'])){
+ $this->cur_dialog = new glpiManufacturer($this->config,$this->dn);
+ $this->dialog = true;
+ }
+
+ /* Close manufacturer editing dialog
+ */
+ if(isset($_POST['close_edit_manufacturer'])){
+ $this->dialog = false;
+ $this->cur_dialog = false;
+ }
+
+
+ /* ##########################################################################
+ * Technical responsible person
+ * Contact person
+ * Dialog
+ */
+
+ /* Show dialog to select a new contact person
+ * Select a contact person
+ */
+ if(isset($_POST['SelectContactPerson'])){
+ $this->addUser = "contact";
+ $this->cur_dialog= new glpiSelectUser($this->config,$this->dn);
+ }
+
+ /* Selecte technical responsible person
+ */
+ if(isset($_POST['SelectTechPerson'])){
+ $this->addUser ="tech";
+ $this->cur_dialog= new glpiSelectUser($this->config,$this->dn);
+ }
+
+ /* Abort user selection
+ */
+ if(isset($_POST['SelectUserCancel'])){
+ $this->dialog = false;
+ $this->addUser ="";
+ $this->cur_dialog = false;
+ }
+
+ /* Technical responsible/contact person selected */
+ if(isset($_GET['act'])&&($_GET['act']=="user_tech_num")){
+
+ /* Get posted id */
+ $id = base64_decode($_GET['id']);
+
+ /* Check if user is already created in glpi database */
+ if(!in_array($id,$users)){
+
+ /* If this user doesn't exists in glpi db, we must create him */
+ $atr = $ldap->fetch($ldap->cat($id));
+ $tmp = array();
+ $use = array( "cn" =>"name",
+ "mail" =>"email",
+ "telephoneNumber" =>"phone");
+
+ /* Create array */
+ foreach($use as $gosa => $glpi){
+ if(isset($atr[$gosa])){
+ $tmp[$glpi]= $atr[$gosa][0];
+ }
+ }
+
+ /* Add this user */
+ $this->handle->addUser($tmp,$id);
+ }
+
+ /* Re-read users */
+ $users = ($this->handle->getUsers());
+
+ /* Get user */
+ $tmp = array_flip($users);
+ $id=$tmp[$id];
+
+ /* Use user id, close dialog */
+ if($this->addUser == "tech"){
+ $this->tech_num = $id;
+ }else{
+ $this->contact_num = $id;
+ }
+ $this->cur_dialog = false;
+ $this->dialog= false;
+ }
+
+
+ /* ##########################################################################
+ * Handle attachments
+ */
+
+ /* Attachment pool was closed with use
+ */
+ if(isset($_POST['UseAttachment'])){
+ if(count($this->cur_dialog->check())){
+ foreach($this->cur_dialog->check() as $msg){
+ print_red($msg);
+ }
+ }else{
+ $this->cur_dialog->save_object();
+ $this->usedAttachments = $this->cur_dialog->save();
+ $this->cur_dialog = false;
+ $this->edit_type = false;
+ }
+ }
+
+ /* Attachment pool was closed with abort
+ */
+ if(isset($_POST['AbortAttachment'])){
+ $this->cur_dialog = false;
+ $this->edit_type = false;
+ }
+
+ /* Open Attachment pool to add/edit Attachments
+ */
+ if(isset($_POST['AddAttachment'])){
+ $this->cur_dialog = new glpiAttachmentPool($this->config,$this->dn,$this->usedAttachments);
+ $this->dialog = true;
+ }
+
+ /* Remove Attachment from this tab
+ */
+ if((isset($_POST['RemoveAttachment']))&&(isset($_POST['Attachments']))){
+ if(isset($this->usedAttachments[$_POST['Attachments']])){
+ unset($this->usedAttachments[$_POST['Attachments']]);
+ }
+ }
+
+ /* ##########################################################################
+ * Draw Dialogs
+ */
+ /* if( cur_dialog != false || cur_dialog != NULL)
+ * There is a dialog which wants to be displayed
+ */
+ if($this->cur_dialog){
+ $this->cur_dialog->save_object();
+ $this->dialog=true;
+ $this->cur_dialog->parent = &$this;
+ return($this->cur_dialog->execute());
+ }else{
+ $this->dialog= false;
+ }
+
+
+ /* ##########################################################################
+ * Assign listbox / checkbox .... values to smarty
+ */
+ /* Assign smarty defaults */
+ foreach(array("PrinterTypes","PrinterTypeKeys","Manufacturers","TechnicalResponsibles","Attachments") as $attr){
+ $smarty->assign($attr,array());
+ $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
+ }
+
+ /* Assign some vars to smarty
+ */
+ foreach(array("type","FK_glpi_enterprise","tech_num","contact_num","flags_serial","flags_par","flags_usb") as $attr){
+ $smarty->assign($attr,"");
+ $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
+ }
+
+
+ /* Assign ACLs to smarty*/
+ foreach($this->attributes as $attr){
+ $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
+ }
+
+ $smarty->assign("comments", $this->comments);
+ $smarty->assign("flags_serial", $this->flags_serial);
+ $smarty->assign("flags_par", $this->flags_par);
+ $smarty->assign("flags_usb", $this->flags_usb);
+
+ /* Assign system types
+ */
+ $smarty->assign("PrinterTypes", $this->handle->getPrinterTypes());
+ $smarty->assign("PrinterTypeKeys", array_flip($this->handle->getPrinterTypes()));
+ $smarty->assign("type", $this->type);
+
+ /* Append manufacturers
+ */
+ $smarty->assign("ManufacturerKeys", array_flip($this->handle->getEnterprises()));
+ $smarty->assign("Manufacturers", $this->handle->getEnterprises());
+ $smarty->assign("FK_glpi_enterprise", $this->FK_glpi_enterprise);
+
+ /* Assign used Attachments
+ */
+ $smarty->assign("Attachments", $this->getUsedAttachments());
+ $smarty->assign("AttachmentKeys", array_flip($this->getUsedAttachments()));
+
+
+ /* ##########################################################################
+ * Assign contact and technical responsible person
+ */
+ if(isset($users[$this->contact_num])){
+ $tr = $ldap->fetch($ldap->cat($users[$this->contact_num]));
+ $str = "";
+ if(isset($tr['givenName'][0])){ $str .= $tr['givenName'][0]." "; }
+ if(isset($tr['sn'][0])) { $str .= $tr['sn'][0]." "; }
+ if(isset($tr['uid'][0])){ $str .= "[".$tr['uid'][0]."]"; }
+ $smarty->assign("contact_num", $str);
+ }else{
+ $smarty->assign("contact_num", _("N/A"));
+ }
+
+ /* Handle tech person
+ Assign name ... to smarty, if set
+ */
+ if(isset($users[$this->tech_num])){
+ $tr = $ldap->fetch($ldap->cat($users[$this->tech_num]));
+ $str = "";
+ if(isset($tr['givenName'][0])){ $str .= $tr['givenName'][0]." "; }
+ if(isset($tr['sn'][0])) { $str .= $tr['sn'][0]." "; }
+ if(isset($tr['uid'][0])){ $str .= "[".$tr['uid'][0]."]"; }
+ $smarty->assign("tech_num", $str);
+ }else{
+ $smarty->assign("tech_num", _("N/A"));
+ }
+
+ $display.= $smarty->fetch(get_template_path('glpiPrinter.tpl', TRUE));
+ return($display);
+ }
+
+ function remove_from_parent()
+ {
+ $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
+ if($this->initially_was_account){
+ $this->handle->removePrinterInformations($this->dn);
+ }
+ }
+
+
+ /* Save data to object */
+ function save_object()
+ {
+ 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;
+ }
+ }
+
+ }
+
+
+ /* Check supplied data */
+ function check()
+ {
+ $message= array();
+
+ // if($this->TechnicalResponsible == ""){
+ // $message[] = _("Please select a technical responsible person for this entry.");
+ // }
+
+ return ($message);
+ }
+
+ /* Save to LDAP */
+ function save()
+ {
+ if($this->is_account){
+ $attrs = array();
+ $this->date_mod = date("Y-m-d H:i:s");
+ foreach($this->attributes as $attr){
+ $attrs[$attr] = $this->$attr;
+ }
+ $attrs['name'] = $this->dn;
+ unset($attrs['ID']);
+ $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
+ if($this->initially_was_account&&$this->is_account){
+ $this->handle->updatePrinterInformations($attrs,$this->dn);
+ }elseif($this->is_account){
+ $this->handle->addPrinterInformations($attrs,$this->dn);
+ }
+ $tmp = $this->handle->getPrinterInformations($this->dn);
+ $this->handle->addAttachmentsToPrinter($this->usedAttachments,$tmp[0]['ID']);
+ }
+ }
+
+ /* Return used attachments */
+ function getUsedAttachments()
+ {
+ $atts =$this->handle->getAttachments();
+ $ret = array();
+ foreach($atts as $entry){
+ if(in_array($entry['ID'],$this->usedAttachments)){
+
+ $cm ="";
+ if(isset($entry['comment'])){
+ $cm=" [".$entry['comment']."]";
+ }
+ if(isset($entry['mime'])){
+ $cm.=" -".$entry['mime']."";
+ }
+
+ $ret[$entry['ID']]= $entry['name'].$cm;
+ }
+ }
+ 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
--- /dev/null
@@ -0,0 +1,106 @@
+<table summary="" style="width:100%;">
+ <tr>
+ <td style="width:50%;vertical-align: top;">
+ <!--Upper left-->
+
+ <h2>{t}Generic{/t}</h2>
+ <table summary="" cellpadding=5>
+ <tr>
+ <td width="150">{t}Printer type{/t}
+ </td>
+ <td>
+ <select name="type" {$typeACL}>
+ {html_options values=$PrinterTypeKeys output=$PrinterTypes selected=$type}
+ </select>
+ <input type="submit" value="{t}edit{/t}" name="edit_type" {$typeACL}>
+ </td>
+ </tr>
+ <tr>
+ <td>{t}Manufacturer{/t}
+ </td>
+ <td>
+ <select name="FK_glpi_enterprise" {$FK_glpi_enterpriseACL}>
+ {html_options values=$ManufacturerKeys output=$Manufacturers selected=$FK_glpi_enterprise}
+ </select>
+ <input type="submit" value="{t}edit{/t}" name="edit_manufacturer" {$FK_glpi_enterpriseACL}>
+ </td>
+ </tr>
+ </table>
+ <p class="seperator" > </p>
+ <h2>{t}Contacts{/t}</h2>
+ <table summary="" cellpadding=5>
+ <tr>
+ <td>{t}Technical responsible{/t}
+ </td>
+ <td>
+ <i>{$tech_num} </i>
+ <input type="submit" value="{t}Choose{/t}" name="SelectTechPerson" {$tech_numACL}>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ {t}Contact person{/t}
+ </td>
+ <td>
+ <i>{$contact_num} </i>
+ <input {$contact_numACL} type="submit" name="SelectContactPerson" value="{t}Edit{/t}">
+ </td>
+ </tr>
+ </table>
+ <p class="seperator" > </p>
+ <h2>{t}Supported interfaces{/t}</h2>
+ <table summary="" width="100%">
+ <tr>
+ <td width="20">
+ <input type="checkbox" name="flags_serial" {if $flags_serial=="1"} checked {/if} value="1">
+ </td>
+ <td>
+ {t}Serial{/t}
+ </td>
+ </tr>
+ <tr>
+ <td width="20">
+ <input type="checkbox" name="flags_par" {if $flags_par=="1"} checked {/if} value="1">
+ </td>
+ <td>
+ {t}Parallel{/t}
+ </td>
+ </tr>
+ <tr>
+ <td width="20">
+ <input type="checkbox" name="flags_usb" {if $flags_usb=="1"} checked {/if} value="1">
+ </td>
+ <td>
+ {t}USB{/t}
+ </td>
+ </tr>
+ </table>
+ </td>
+ <td style="border-left: 1px solid rgb(160, 160, 160); vertical-align: top; padding-right: 5px;">
+ <h2>{t}Information{/t}</h2>
+ <table summary="" width="100%">
+ <tr>
+ <td style="vertical-align: top;">
+ {t}Comments{/t}
+ </td>
+ <td>
+ <textarea name="comments" style="width:100%;height:110px;" {$commentsACL}>{$comments}</textarea>
+ </td>
+ </tr>
+ </table>
+ <p class="seperator" > </p>
+ <h2>{t}Attachments{/t}</h2>
+ <table summary="" width="100%">
+ <tr>
+ <td>
+ <select name="Attachments" {$AttachmentsACL} style="height:120px;width:100%;" multiple>
+ {html_options values=$AttachmentKeys output=$Attachments}
+ </select>
+ <input name="AddAttachment" value="{t}Add{/t}" type="submit">
+ <input name="RemoveAttachment" value="{t}Remove{/t}" type="submit">
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+</table>
diff --git a/plugins/admin/systems/glpi_edit_printer_type.tpl b/plugins/admin/systems/glpi_edit_printer_type.tpl
--- /dev/null
@@ -0,0 +1,15 @@
+<br>
+ <select name="select_type" size="8" style="width:80%">
+ {html_options values=$PrinterTypeKeys output=$PrinterTypes}
+ </select><br>
+ <input name="type_string">
+ <input type="submit" name="add_type" value="{t}Add{/t}" >
+ <input type="submit" name="rename_type" value="{t}Rename{/t}" >
+ <input type="submit" name="del_type" value="{t}Delete{/t}" >
+
+<p class="seperator"> </p>
+<div align="right">
+<p>
+<input name="close_edit_type" value="{t}close{/t}" type="submit">
+</p>
+</div>
index a1e85ebb691aec55f2e8a3eac849594bf46a46b8..d06c98e26e8168cbf6723fbaf8b0c61cb9aae996 100644 (file)
$this->by_object[$key]->dn= $this->dn;
}
- tabs::save(TRUE);
+ tabs::save(FALSE);
}
}