From: hickert Date: Tue, 9 Oct 2007 11:40:30 +0000 (+0000) Subject: Updated hotplug hanlding for users X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=e9f675bfb89f05bf0501e8a355798763443f3149;p=gosa.git Updated hotplug hanlding for users git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@7469 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/plugins/personal/environment/class_environment.inc b/plugins/personal/environment/class_environment.inc index aafbd288d..9d618039e 100644 --- a/plugins/personal/environment/class_environment.inc +++ b/plugins/personal/environment/class_environment.inc @@ -68,7 +68,7 @@ class environment extends plugin var $CopyPasteVars = array("gotoHotplugDevices","gotoAvailableShares","gotoShareSelections","gotoPrinterSel","gotoProfileFlagL","gotoXResolutions","gotoProfileFlagC","gotoProfileServers","useProfile","is_group","in_dialog","OrigCn"); - var $attributes = array("uid","gotoProfileServer","gotoProfileFlags","gotoHotplugDevice", + var $attributes = array("uid","gotoProfileServer","gotoProfileFlags","gotoHotplugDeviceDN", "gotoXResolution","gotoProfileQuota", "gotoLogonScripts","gotoLogonScript", "gotoPrinter", "gosaDefaultPrinter", @@ -120,37 +120,22 @@ class environment extends plugin for($i = 0 ; $i < $this->attrs['gotoHotplugDeviceDN']['count'] ; $i ++){ $ldap->cat(base64_decode($this->attrs['gotoHotplugDeviceDN'][$i])); $attrs = $ldap->fetch(); - $this->gotoHotplugDevices[$attrs['cn'][0]] = array('name' => $attrs['cn'][0], 'id' => rand(1,10)); + + if(isset($attrs['gotoHotplugDevice'][0])){ + $tmp = preg_split("/\|/",$attrs['gotoHotplugDevice'][0]); + $tmp2 = array(); + $tmp2['name'] = $attrs['cn'][0]; + $tmp2['description'] = $tmp[0]; + $tmp2['id'] = $tmp[1]; + $tmp2['produkt'] = $tmp[2]; + $tmp2['vendor'] = $tmp[3]; + $tmp2['dn'] = $attrs['dn']; + $this->gotoHotplugDevices[] = $tmp2; + } } } - - -# /* prepare hotplugs */ -# if((isset($this->attrs['gotoHotplugDevice']))&&(is_array($this->attrs['gotoHotplugDevice']))){ -# unset($this->attrs['gotoHotplugDevice']['count']); -# foreach($this->attrs['gotoHotplugDevice'] as $device){ -# $tmp = $tmp2 = array(); -# $tmp = split("\|",$device); -# $tmp2['name'] = $tmp[0]; -# $tmp2['description'] = $tmp[1]; -# $tmp2['id'] = $tmp[2]; -# -# /* Produkt ID */ -# if(!isset($tmp[3])){ -# $tmp[3] = ""; -# } -# /* Vendor ID */ -# if(!isset($tmp[4])){ -# $tmp[4] = ""; -# } -# -# $tmp2['produkt'] = $tmp[3]; -# $tmp2['vendor'] = $tmp[4]; -# -# $this->gotoHotplugDevices[$tmp[0]]=$tmp2; -# } -# } + /* prepare LogonScripts */ if((isset($this->attrs['gotoLogonScript']))&&(is_array($this->attrs['gotoLogonScript']))){ unset($this->attrs['gotoLogonScript']['count']); @@ -313,8 +298,6 @@ class environment extends plugin function execute() { - - /* Call parent execute */ plugin::execute(); /* Log view */ @@ -749,12 +732,6 @@ class environment extends plugin * Editing an entry will open a dialog where the informations about the selcted entry can be changed */ - /* If there is a new entry wanted, open a new entry by initilising the dialog */ - if((isset($_POST['gotoHotplugDeviceNew'])) && ($this->acl_is_writeable("gotoHotplugDevice"))){ - $this->dialog = new hotplugDialog($this->config,$this->dn); - $this->is_dialog = true; - } - /* We have to delete the selected hotplug from the list*/ if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice_post'])) && $this->acl_is_writeable("gotoHotplugDevice")){ if($this->acl_is_writeable("gotoHotplugDevice")){ @@ -770,7 +747,7 @@ class environment extends plugin foreach($this->gotoHotplugDevices as $plugs){ $tmp[] = $plugs['name']; } - $this->dialog = new hotplugDialog($this->config,$this->dn,true,$tmp); + $this->dialog = new hotplugDialog($this->config,$tmp); $this->is_dialog = true; } @@ -1167,12 +1144,7 @@ class environment extends plugin /* Prepare HotPlug devices */ $this->attrs['gotoHotplugDevice'] = array(); foreach($this->gotoHotplugDevices as $name => $device){ - - $tmp= $device['name']."|".$device['description']."|".$device['id']; - if (isset($device['produkt']) && isset($device['vendor'])){ - $tmp.= "|".$device['produkt']."|".$device['vendor']; - } - $this->attrs['gotoHotplugDevice'][]= $tmp; + $this->attrs['gotoHotplugDeviceDN'][]= base64_encode($device['dn']); } /* Prepare LogonScripts */ diff --git a/plugins/personal/environment/class_hotplugDialog.inc b/plugins/personal/environment/class_hotplugDialog.inc index 2e69647fb..a4b446b7b 100644 --- a/plugins/personal/environment/class_hotplugDialog.inc +++ b/plugins/personal/environment/class_hotplugDialog.inc @@ -8,17 +8,6 @@ class hotplugDialog extends plugin var $cli_parameters = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser"); /* attribute list for save action */ - var $ignore_account = TRUE; - var $attributes = array("HOT_name","HOT_description","HOT_id","HOT_produkt","HOT_vendor"); - var $objectclasses = array("whatever"); - var $use_existing = false; - - var $HOT_name = ""; - var $HOT_description = ""; - var $HOT_id = "0x0000"; - var $HOT_produkt = ""; - var $HOT_vendor = ""; - var $hotplugDevices = ""; var $hotplugDeviceList = array(); var $regex = "*"; @@ -26,202 +15,97 @@ class hotplugDialog extends plugin var $deplist = "/"; var $skipThese = array(); - function hotplugDialog (&$config, $dn= NULL,$use_existing=false ,$skipThese = array()) + function hotplugDialog (&$config,$skipThese = array()) { - $this->use_existing = $use_existing; - $this->skipThese = $skipThese; - plugin::plugin ($config, $dn); - $this->depselect = $this->config->current['BASE']; + $this->skipThese = $skipThese; + $this->config = $config; + $this->depselect = $_SESSION['CurrentMainBase']; } function execute() { - /* Call parent execute */ - plugin::execute(); + /* Call parent execute */ + plugin::execute(); /* Fill templating stuff */ $smarty= get_smarty(); $display= ""; - foreach($this->attributes as $s_attr){ - $smarty->assign($s_attr,$this->$s_attr); - } - - if($this->use_existing){ - - if(isset($_POST['dialogissubmitted'])){ - $this->regex=$_POST['regexHot']; - $this->depselect = $_POST['depselectHot']; - } - - if((isset($_GET['search']))&&(!empty($_GET['search']))){ - $this->regex=$_GET['search']."*"; - $this->regex=preg_replace("/\*\*/","*",$this->regex); - } - - $this->deplist=$this->config->idepartments; - - $this->hotplugDevices = $this->getHotplugs(); - $smarty->assign("regexHot" ,$this->regex); - $smarty->assign("deplistHot" ,$this->deplist); - $smarty->assign("depselectHot",$this->depselect); - $smarty->assign("apply", apply_filter()); - $smarty->assign("alphabet", generate_alphabet()); - $smarty->assign("search_image", get_template_path('images/search.png')); - $smarty->assign("tree_image", get_template_path('images/tree.png')); - $smarty->assign("launchimage", get_template_path('images/small_filter.png')); - $smarty->assign("deplist", $this->config->idepartments); - - - $smarty->assign("hotplugDevices",$this->hotplugDevices); - $smarty->assign("hotplugDeviceKeys",array_flip($this->hotplugDevices)); - $display.= $smarty->fetch(get_template_path('hotplugDialog.tpl', TRUE,dirname(__FILE__))); - }else{ - $display.= $smarty->fetch(get_template_path('hotplugDialogNew.tpl', TRUE,dirname(__FILE__))); - } - return($display); - } - - function remove_from_parent() - { - /* This cannot be removed... */ - } - - - /* Save data to object */ - function save_object() - { if(isset($_POST['dialogissubmitted'])){ - plugin::save_object(); - foreach($this->attributes as $s_attr){ - if(isset($_POST[$s_attr])){ - if(in_array($s_attr,array("HOT_produkt","HOT_vendor"))){ - $this->$s_attr = strtolower(stripslashes($_POST[$s_attr])); - }else{ - $this->$s_attr = stripslashes($_POST[$s_attr]); - } - }else{ - $this->$s_attr = false; - } - } + $this->regex=$_POST['regexHot']; + $this->depselect = $_POST['depselectHot']; } - } - - - /* Check supplied data */ - function check() - { - /* Call common method to give check the hook */ - $message= plugin::check(); - if(!$this->use_existing){ - - if(empty($this->HOT_name)||(preg_match("/[^a-z0-9]/i",$this->HOT_name))){ - $message[]=_("Please specify a valid name. Only 0-9 a-Z is allowed."); - } - if(preg_match("/[^a-z0-9!\"?.,;:-_\(\) ]/i",$this->HOT_description)){ - $message[]=_("Invalid character in description. Please specify a valid description."); - } - - if(empty($this->HOT_id) || preg_match("/[\|\*]/i",$this->HOT_id)){ - $message[]=_("Please specify a valid iSerial."); - } - if(empty($this->HOT_vendor) || !$this->is_2byteHex($this->HOT_vendor)){ - $message[]=_("Please specify a valid vendor ID. (2 byte hex like '0xFFFF')"); - } - if(empty($this->HOT_produkt) || !$this->is_2byteHex($this->HOT_produkt)){ - $message[]=_("Please specify a valid product ID. (2 byte hex like '0xFFFF')"); - } + if((isset($_GET['search']))&&(!empty($_GET['search']))){ + $this->regex=$_GET['search']."*"; + $this->regex=preg_replace("/\*\*/","*",$this->regex); + } - $ldap = $this->config->get_ldap_link(); - $ldap->search("(&(objectClass=gotoEnvironment)(gotoHotplugDevice=".$this->HOT_name."*))",array("gotoHotplugDevice")); - if($ldap->count()){ - $message[]=_("An Entry with this name already exists."); - } + $this->deplist=$this->config->idepartments; - }else{ - if((!isset($_POST['hotplugName']))||(empty($_POST['hotplugName']))){ - $message[] = _("Please select an entry or press cancel."); - } - } + $this->hotplugDevices = $this->getHotplugs(); + $smarty->assign("regexHot" ,$this->regex); + $smarty->assign("deplistHot" ,$this->deplist); + $smarty->assign("depselectHot",$this->depselect); + $smarty->assign("apply", apply_filter()); + $smarty->assign("alphabet", generate_alphabet()); + $smarty->assign("search_image", get_template_path('images/search.png')); + $smarty->assign("tree_image", get_template_path('images/tree.png')); + $smarty->assign("launchimage", get_template_path('images/small_filter.png')); + $smarty->assign("deplist", $this->config->idepartments); - return ($message); - } - function is_2byteHex($str) - { - return empty($str) || preg_match("/^(0x|x|)[a-f0-9][a-f0-9][a-f0-9][a-f0-9]/i",$str); + $smarty->assign("hotplugDevices",$this->hotplugDevices); + $smarty->assign("hotplugDeviceKeys",array_flip($this->hotplugDevices)); + $display.= $smarty->fetch(get_template_path('hotplugDialog.tpl', TRUE,dirname(__FILE__))); + return($display); } - - /* Save to LDAP */ function save() { - /* return generated entry from input fields*/ - if(!$this->use_existing){ - $a_return=array(); - $a_return[$this->HOT_name]['name'] = $this->HOT_name; - $a_return[$this->HOT_name]['description'] = $this->HOT_description; - $a_return[$this->HOT_name]['id'] = $this->HOT_id; - $a_return[$this->HOT_name]['produkt'] = $this->HOT_produkt; - $a_return[$this->HOT_name]['vendor'] = $this->HOT_vendor; - return($a_return); - }else{ - $entries = array(); - foreach($_POST['hotplugName'] as $name){ - $entries[$name] = $this->hotplugDeviceList[$name]; - } - return $entries; + $entries = array(); + foreach($_POST['hotplugName'] as $name){ + $entries[$name] = $this->hotplugDeviceList[$name]; } + return $entries; } - function getHotplugs(){ + function getHotplugs() + { $ldap= $this->config->get_ldap_link(); $ldap->cd($this->depselect); - - $ldap->search("(&(objectClass=gotoEnvironment)(gotoHotplugDevice=".$this->regex."))",array("gotoHotplugDevice")); + $ldap->search("(&(objectClass=gotoDevice)(|(cn=".$this->regex.")(description=".$this->regex.")))",array("gotoHotplugDevice","cn","dn")); $a_return = array(); $this->hotplugDeviceList = array(); while($attr = $ldap->fetch()){ - if(isset($attr['gotoHotplugDevice'])){ - unset($attr['gotoHotplugDevice']['count']); - foreach($attr['gotoHotplugDevice'] as $device){ - $tmp =$tmp2= array(); - $tmp = split("\|",$device); + + if(isset($attr['gotoHotplugDevice'][0])){ + + $hot_plug = $attr['gotoHotplugDevice'][0]; + $tmp = preg_split("/\|/",$hot_plug); + $tmp2 = array(); - if(preg_match("/^".str_replace("*","",$this->regex).".*/i",$tmp[0])){ - - if(in_array($tmp[0],$this->skipThese)) continue; - - $a_return[$tmp[0]]= $tmp[0]." [".$tmp[1]."] ".$tmp[2]; - - $tmp2['name'] = $tmp[0]; - $tmp2['description'] = $tmp[1]; - $tmp2['id'] = $tmp[2]; - - /* Produkt ID */ - if(!isset($tmp[3])){ - $tmp[3] = ""; - } - /* Vendor ID */ - if(!isset($tmp[4])){ - $tmp[4] = ""; - } - - $tmp2['produkt'] = $tmp[3]; - $tmp2['vendor'] = $tmp[4]; - - $this->hotplugDeviceList[$tmp[0]]=$tmp2; - } + if(in_array($attr['cn'][0],$this->skipThese)){ + continue; } + + $tmp2['name'] = $attr['cn'][0]; + $tmp2['description'] = $tmp[0]; + $tmp2['id'] = $tmp[1]; + $tmp2['produkt'] = $tmp[2]; + $tmp2['vendor'] = $tmp[3]; + $tmp2['dn'] = $attr['dn']; + + $a_return[$attr['cn'][0]]= $attr['cn'][0]." [".$tmp[0]."] ".$tmp[1]; + + $this->hotplugDeviceList[$attr['cn'][0]]=$tmp2; } } - return($a_return); + return($a_return); } - } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: diff --git a/plugins/personal/environment/environment.tpl b/plugins/personal/environment/environment.tpl index 391e3acdb..9cd024de5 100644 --- a/plugins/personal/environment/environment.tpl +++ b/plugins/personal/environment/environment.tpl @@ -257,9 +257,6 @@ -{render acl=$gotoHotplugDeviceACL} - -{/render} {render acl=$gotoHotplugDeviceACL} {/render} diff --git a/plugins/personal/environment/hotplugDialogNew.tpl b/plugins/personal/environment/hotplugDialogNew.tpl deleted file mode 100644 index 93a3b12c4..000000000 --- a/plugins/personal/environment/hotplugDialogNew.tpl +++ /dev/null @@ -1,61 +0,0 @@ -

 {t}Create new hotplug entry{/t}

- - - - - - -
- - - - - - - - - -
{$must} - - -
- - -
-
- - - - - - - - - - - - - - -
{$must} - - -  
{$must} - - -
{$must} - - -
-
-

 

-

- - -

- -