X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Fadmin%2Fsystems%2Fclass_glpiAccount.inc;h=9ff5019138a6059b2d135fd975a33db5767d911d;hb=8edf1b0390149b39682c7e02c394fec56940874d;hp=ec997df529011ea70a5d8da4efbdedecbd93caee;hpb=2a82957349a71287a416690ad1db76113fadd755;p=gosa.git diff --git a/plugins/admin/systems/class_glpiAccount.inc b/plugins/admin/systems/class_glpiAccount.inc index ec997df52..9ff501913 100644 --- a/plugins/admin/systems/class_glpiAccount.inc +++ b/plugins/admin/systems/class_glpiAccount.inc @@ -36,6 +36,10 @@ class glpiAccount extends plugin var $FK_glpi_enterprise = 0; // Manufacturer id var $deleted = "N"; // Deleted entries should have this set to Y + var $renameTypeDialog = false; + var $renameOSDialog = false; + var $select_type ; + /* Not necessary, cause we use mysql databse */ var $objectclasses= array("whatever"); @@ -60,9 +64,9 @@ class glpiAccount extends plugin /* Contructor Sets default values and checks if we already have an existing glpi account */ - function glpiAccount ($config, $dn= NULL) + function glpiAccount ($config, $dn= NULL, $parent= NULL) { - plugin::plugin ($config, $dn); + plugin::plugin ($config, $dn, $parent); $this->ui= get_userinfo(); /* Abort class construction, if no db is defined */ @@ -275,6 +279,11 @@ class glpiAccount extends plugin $this->dialog = false; } + if(isset($_POST['Rename_Cancel'])){ + $this->renameTypeDialog = false; + $this->renameOSDialog = false; + } + /* This appends a new system to our sytem types */ if((isset($_POST['add_type']))&&(!empty($_POST['type_string']))){ @@ -308,19 +317,40 @@ class glpiAccount extends plugin /* Rename selected system type to given string */ - if((isset($_POST['rename_type']))&&(!empty($_POST['select_type']))&&(!empty($_POST['type_string']))){ + if(isset($_POST['Rename_type_OK'])){ $attr = $this->handle->getSystemTypes(); - if(in_array(trim($_POST['type_string']),$attr)){ + if(in_array(trim($_POST['string']),$attr)){ print_red(_("Rename failed, this system type name is already used.")) ; }else{ - $this->handle->updateSystemType($_POST['type_string'],trim($_POST['select_type'])); + $this->renameTypeDialog = false; + $this->handle->updateSystemType($_POST['string'],trim($this->select_type)); + } + } + + + if((isset($_POST['rename_type'])&&(!empty($_POST['select_type'])))||($this->renameTypeDialog)){ + if(isset($_POST['select_type'])){ + $this->select_type = $_POST['select_type']; + } + $this->renameTypeDialog = true; + $tmp = $this->handle->getSystemTypes(); + + $smarty->assign("string",$tmp[$this->select_type]); + if(isset($_POST['string'])){ + $smarty->assign("string",$_POST['string']); } + $smarty->assign("Method","rename"); + $display= $smarty->fetch(get_template_path('glpi_edit_type.tpl', TRUE)); + return($display); } + + /* Someone wants to edit the system types ... So, lets open a new dialog which provides some buttons to edit the types */ if($this->edit_type){ + $smarty->assign("Method","edit"); $smarty->assign("SystemTypes", $this->handle->getSystemTypes()); $smarty->assign("SystemTypeKeys", array_flip($this->handle->getSystemTypes())); $display= $smarty->fetch(get_template_path('glpi_edit_type.tpl', TRUE)); @@ -377,24 +407,43 @@ class glpiAccount extends plugin /* Rename selected os to given string */ - if((isset($_POST['rename_os']))&&(!empty($_POST['select_os']))&&(!empty($_POST['is_string']))){ + if(isset($_POST['Rename_os_OK'])){ $attr = $this->handle->getOSTypes(); - if(in_array(trim($_POST['is_string']),$attr)){ + if(in_array(trim($_POST['string']),$attr)){ print_red(_("Updating operating system failed, specifed name is already used.")) ; }else{ - $this->handle->updateOS($_POST['is_string'],$_POST['select_os']); + $this->handle->updateOS($_POST['string'],$this->select_type); + $this->renameOSDialog = false; } } + if((isset($_POST['rename_os'])&&(!empty($_POST['select_os'])))||($this->renameOSDialog)){ + if(isset($_POST['select_os'])){ + $this->select_type = $_POST['select_os']; + } + $this->renameOSDialog = true; + $tmp = $this->handle->getOSTypes(); + + $smarty->assign("string",$tmp[$this->select_type]); + if(isset($_POST['string'])){ + $smarty->assign("string",$_POST['string']); + } + $smarty->assign("Method","rename"); + $display= $smarty->fetch(get_template_path('glpi_edit_os.tpl', TRUE)); + return($display); + } /* Open dialog to edit os types */ if($this->edit_os){ - $smarty->assign("OSKeys", array_flip($this->handle->getOSTypes())); - $smarty->assign("OSs", $this->handle->getOSTypes()); + $smarty->assign("Method","edit"); + $smarty->assign("OSs", $this->handle->getOSTypes()); + $smarty->assign("OSKeys", array_flip($this->handle->getOSTypes())); $display= $smarty->fetch(get_template_path('glpi_edit_os.tpl', TRUE)); return($display); } + + /* Show dialog to select a new contact person * Select a contact person */ @@ -443,7 +492,8 @@ class glpiAccount extends plugin if(!in_array($id,$users)){ /* If this user doesn't exists in glpi db, we must create him */ - $atr = $ldap->fetch($ldap->cat($id)); + $ldap->cat($id, array('cn', 'mail', 'telephoneNumber')); + $atr = $ldap->fetch(); $tmp = array(); $use = array( "cn" =>"name", "mail" =>"email", @@ -512,11 +562,11 @@ class glpiAccount extends plugin /* 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.")); + $display= $this->show_header(_("Remove inventory"), + _("This device has inventory informations 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.")); + $display= $this->show_header(_("Add inventory"), + _("This device has inventory informations disabled. You can enable them by clicking below.")); return ($display); } @@ -572,7 +622,8 @@ class glpiAccount extends plugin Assign name ... to smarty, if set */ if(isset($users[$this->contact_num])){ - $tr = $ldap->fetch($ldap->cat($users[$this->contact_num])); + $ldap->cat($users[$this->contact_num], array('givenName', 'sn', 'uid')); + $tr = $ldap->fetch(); $str = ""; if(isset($tr['givenName'][0])){ $str .= $tr['givenName'][0]." "; } if(isset($tr['sn'][0])) { $str .= $tr['sn'][0]." "; } @@ -586,7 +637,8 @@ class glpiAccount extends plugin Assign name ... to smarty, if set */ if(isset($users[$this->tech_num])){ - $tr = $ldap->fetch($ldap->cat($users[$this->tech_num])); + $tr = $ldap->cat($users[$this->tech_num], array('givenName', 'sn', 'uid')); + $tr = $ldap->fetch(); $str = ""; if(isset($tr['givenName'][0])){ $str .= $tr['givenName'][0]." "; } if(isset($tr['sn'][0])) { $str .= $tr['sn'][0]." "; } @@ -603,9 +655,16 @@ class glpiAccount extends plugin function remove_from_parent() { - $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']); - if($this->initialy_was_account){ - $this->handle->removeComputerInformations($this->dn); + if(!$this->initialy_was_account){ + return; + } + if(function_exists("mysql_pconnect")){ + $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']); + if($this->initialy_was_account){ + $this->handle->removeComputerInformations($this->dn); + } + }else{ + print_red(_("Can't remove glpi account, while mysql extension is missing.")); } } @@ -634,7 +693,7 @@ class glpiAccount extends plugin plugin::save_object(); foreach($this->attributes as $attrs){ if(isset($_POST[$attrs])){ - $this->$attrs = $_POST[$attrs]; + $this->$attrs = stripslashes ($_POST[$attrs]); } } } @@ -643,7 +702,8 @@ class glpiAccount extends plugin /* Check supplied data */ function check() { - $message= array(); + /* Call common method to give check the hook */ + $message= plugin::check(); // if($this->TechnicalResponsible == ""){ // $message[] = _("Please select a technical responsible person for this entry."); @@ -664,8 +724,10 @@ class glpiAccount extends plugin $attrs['name'] = $this->dn; unset($attrs['ID']); $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']); + + /* check if we have to update, add */ if($this->initialy_was_account&&$this->is_account){ - $this->handle->updateComputerInformations($attrs,$this->dn); + $this->handle->updateComputerInformations($attrs,$this->orig_dn); }elseif($this->is_account){ $this->handle->addComputerInformations($attrs,$this->dn); }