X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Fgofax%2Fblocklists%2Fclass_blocklistManagement.inc;h=63f2dbb77d1af2113f53ec0a2532b2ff3838b067;hb=9b24877b4c1ed66e83811b545b94335ba8a21c33;hp=10a682e84a06b6228d2a9b35c4ffdae270099b4c;hpb=317f1e4c9f590ddfacb40f5d8f7f92283c92e1ba;p=gosa.git diff --git a/plugins/gofax/blocklists/class_blocklistManagement.inc b/plugins/gofax/blocklists/class_blocklistManagement.inc index 10a682e84..63f2dbb77 100644 --- a/plugins/gofax/blocklists/class_blocklistManagement.inc +++ b/plugins/gofax/blocklists/class_blocklistManagement.inc @@ -11,55 +11,50 @@ class blocklist extends plugin var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser"); /* blocklist attributes */ - var $cn= ""; - var $description= ""; - var $type= ""; - var $goFaxBlocklist= array(); - var $base= ""; + var $cn = ""; + var $description = ""; + var $type = ""; + var $base = ""; - /* Headpage attributes */ - var $blocklists= array(); - - /* attribute list for save action */ - var $attributes= array("cn", "description"); - var $objectclasses= array(); + var $goFaxBlocklist = array(); + var $blocklists = array(); + var $attributes = array("cn", "description"); + var $objectclasses = array(); + var $DivListBlocklist = NULL; function blocklist ($config, $ui) { - $this->ui= $ui; - $this->dn= ""; - $this->config= $config; - - /* Get global filter config */ - if (!is_global("blockfilter")){ - $ui= get_userinfo(); - $base= get_base_from_people($ui->dn); - $blockfilter= array("sendlists" => "checked", - "receivelists" => "checked", - "entry" => "*", - "depselect" => $base, - "regex" => "*"); - register_global("blockfilter", $blockfilter); - } + /* Init class */ + $this->ui = $ui; + $this->dn = ""; + $this->config = $config; + + $ui = get_userinfo(); + $acl = get_permissions ($ui->dn, $ui->subtreeACL); + $this->acl = get_module_permission($acl, "blocklists", $ui->dn); + $this->DivListBlocklist = new divListBlocklist($this->config,$this); } function execute() { + /* Call parent execute */ + plugin::execute(); + + /*************** + Init vars + ***************/ + /* Get global smarty instance */ - $smarty= get_smarty(); - $blockfilter = get_global("blockfilter"); // contains Filter Settings + $smarty = get_smarty(); $s_action = ""; // Contains the action to proceed $s_entry = ""; // The value for s_action $base_back = ""; // The Link for Backbutton - /* Start for New List Managment */ - if(isset($_GET['act'])&&($_GET['act']=="dep_open")){ - $s_action="open"; - $s_entry = base64_decode($_GET['dep_id']); - $blockfilter['depselect']= "".$this->config->departments[trim($s_entry)]; - $this->reload(); - } + + /*************** + Fetch posts + ***************/ /* Test Posts */ foreach($_POST as $key => $val){ @@ -72,24 +67,16 @@ class blocklist extends plugin $s_action="edit"; $s_entry = preg_replace("/user_".$s_action."_/i","",$key); // Post for new - }elseif(preg_match("/dep_back.*/i",$key)){ - $s_action="back"; }elseif(preg_match("/user_new.*/",$key)){ $s_action="new"; - }elseif(preg_match("/dep_home.*/i",$key)){ - $s_action="home"; }elseif(preg_match("/user_tplnew.*/i",$key)){ $s_action="new_tpl"; }elseif(preg_match("/user_chgpw.*/i",$key)){ $s_action="change_pw"; $s_entry = preg_replace("/user_chgpw_/i","",$key); - }elseif(preg_match("/dep_root.*/i",$key)){ - $s_action="root"; } } - - if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){ $s_action ="edit"; $s_entry = $_GET['id']; @@ -97,96 +84,80 @@ class blocklist extends plugin $s_entry = preg_replace("/_.$/","",$s_entry); - /* Department changed? */ - if(isset($_POST['depselect']) && $_POST['depselect']){ - $blockfilter['depselect']= $_POST['depselect']; - $this->reload(); - } - /* Homebutton is posted */ - if($s_action=="home"){ - $blockfilter['depselect']=(preg_replace("/^[^,]+,/","",$this->ui->dn)); - $blockfilter['depselect']=(preg_replace("/^[^,]+,/","",$blockfilter['depselect'])); - $this->reload(); - } + /*************** + Cancel some dialogs + ***************/ - if($s_action=="root"){ - $blockfilter['depselect']=($this->config->current['BASE']); - $this->reload(); - } - - /* If Backbutton is Posted */ - if($s_action=="back"){ - $base_back = preg_replace("/^[^,]+,/","",$blockfilter['depselect']); - $base_back = convert_department_dn($base_back); - - if(isset($this->config->departments[trim($base_back)])){ - $blockfilter['depselect']= $this->config->departments[trim($base_back)]; - }else{ - $blockfilter['depselect']= $this->config->departments["/"]; - } - $this->reload(); - } - - register_global("blockfilter", $blockfilter); + /* Cancel dialog */ + if (isset($_POST['edit_cancel']) || + isset($_POST['delete_blocklist_cancel']) || + isset($_POST['delete_blocklist_confirm']) || + isset($_POST['delete_lock'])){ - /* Save data */ - $blockfilter= get_global("blockfilter"); - foreach( array( "entry", "regex") as $type){ - if (isset($_POST[$type])){ - $blockfilter[$type]= $_POST[$type]; + if(!isset($_POST['delete_blocklist_confirm'])){ + $this->clear_fields(); } + del_lock ($this->dn); + unset($_SESSION['objectinfo']); } - if (isset($_POST['depselect'])){ - foreach( array("sendlists", "receivelists") as $type){ - if (isset($_POST[$type])) { - $blockfilter[$type]= "checked"; - } else { - $blockfilter[$type]= ""; - } - } - } - if (isset($_GET['search'])){ - $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*"; - if ($s == "**"){ - $s= "*"; - } - $blockfilter['regex']= $s; - } - register_global("blockfilter", $blockfilter); + + /*************** + Cancel some dialogs + ***************/ /* Create new blocklist? */ if ($s_action=="new"){ $this->clear_fields(); - $this->acl= "#all#"; $this->dn= "new"; plugin::plugin ($this->config, $this->dn); } + + /*************** + Edit blocklist + ***************/ + /* Edit selected blocklist? */ - if ($s_action=="edit"){ + if (($s_action=="edit") && (empty($this->dn))){ $this->clear_fields(); $this->dn=$this->blocklists[$s_entry]['dn']; - $this->acl= get_permissions ($this->dn, $this->ui->subtreeACL); - $this->acl= get_module_permission($this->acl, "blocklists", $this->dn); - plugin::plugin ($this->config, $this->dn); + if (($user= get_lock($this->dn)) != ""){ + $_SESSION['dn']= $this->dn; + //$this->dn =""; + return(gen_locked_message($user, $this->dn)); + } else { +# Lock this dn for editing + add_lock ($this->dn, $this->ui->dn); - /* Load missing lists */ - if (isset($this->attrs["goFaxSBlocklist"])){ - for ($i= 0; $i<$this->attrs["goFaxSBlocklist"]["count"]; $i++){ - $this->goFaxBlocklist[]= $this->attrs["goFaxSBlocklist"][$i]; - } - $this->type= 0; - } elseif (isset($this->attrs["goFaxRBlocklist"])){ - for ($i= 0; $i<$this->attrs["goFaxRBlocklist"]["count"]; $i++){ - $this->goFaxBlocklist[]= $this->attrs["goFaxRBlocklist"][$i]; + plugin::plugin ($this->config, $this->dn); + + /* Load missing lists */ + if (in_array("goFaxSBlock",$this->attrs['objectClass'])){ + if(isset($this->attrs["goFaxSBlocklist"])){ + for ($i= 0; $i<$this->attrs["goFaxSBlocklist"]["count"]; $i++){ + $this->goFaxBlocklist[]= $this->attrs["goFaxSBlocklist"][$i]; + } + } + $this->type= 0; + } elseif (in_array("goFaxRBlock",$this->attrs['objectClass'])){ + if(isset($this->attrs["goFaxRBlocklist"])){ + for ($i= 0; $i<$this->attrs["goFaxRBlocklist"]["count"]; $i++){ + $this->goFaxBlocklist[]= $this->attrs["goFaxRBlocklist"][$i]; + } + } + $this->type= 1; } - $this->type= 1; + $_SESSION['objectinfo']= trim($this->dn); } - $_SESSION['objectinfo']= trim($this->dn); } + + /*************** + Remove blocklist + ***************/ + /* Delete blocklist requested */ if ($s_action=="del"){ $this->dn=$this->blocklists[$s_entry]['dn']; @@ -203,11 +174,14 @@ class blocklist extends plugin } } + + /*************** + Remove blocklist confirmed + ***************/ + /* Finally delete blocklist */ if (isset($_POST['delete_blocklist_confirm'])){ - $acl= get_permissions ($this->dn, $this->ui->subtreeACL); - $acl= get_module_permission($acl, "blocklists", $this->dn); - if (chkacl($acl, "all") == ""){ + if (chkacl($this->acl, "delete") == ""){ $this->remove_from_parent(); gosa_log ("Blocklist object'".$this->dn."' has been removed"); $this->reload (); @@ -216,14 +190,11 @@ class blocklist extends plugin } } - /* Cancel dialog */ - if (isset($_POST['edit_cancel']) || isset($_POST['delete_blocklist_cancel']) || - isset($_POST['delete_blocklist_confirm']) || isset($_POST['delete_lock'])){ - del_lock ($this->dn); - $this->clear_fields(); - unset($_SESSION['objectinfo']); - } + /*************** + Add numer to blocklist + ***************/ + /* Handle interactions: add */ if (isset($_POST['add_number']) && $_POST['number'] != ""){ @@ -234,14 +205,25 @@ class blocklist extends plugin } } + + /*************** + Delete number from list + ***************/ + /* Handle interactions: delete */ if (isset($_POST['delete_number']) && count($_POST['numbers']) > 0){ $this->delNumber ($_POST['numbers']); } + + /*************** + Edit finished + ***************/ + /* What about finish? */ - if (isset($_POST['edit_finish'])){ + if ((isset($_POST['edit_finish'])) && (!empty($this->dn))){ $message= $this->check(); + $this->remove_lock(); /* No errors, save object */ if (count ($message) == 0){ @@ -253,7 +235,6 @@ class blocklist extends plugin $this->save (); gosa_log ("Blocklist object'".$this->dn."' has been saved"); - $this->acl= "#none#"; $this->dn= ""; del_lock ($this->ui->dn); unset($_SESSION['objectinfo']); @@ -263,199 +244,111 @@ class blocklist extends plugin } } - /* Headpage or normal plugin screen? */ - if ($this->dn == ""){ - /* Check sorting variable */ - $this->reload(); - - /* Check for exeeded sizelimit */ - if (($message= check_sizelimit()) != ""){ - return($message); - } - - $options= ""; - foreach ($this->config->idepartments as $key => $value){ - if ($blockfilter['depselect'] == $key){ - $options.= ""; - } else { - $options.= ""; - } - } - - - /* NEW LIST MANAGMENT */ - $listhead = "
". - "  ". - "  ". - "  ". - "  ". - "  ". - "  "._("Current base")." ". - "  ". - "
"; + /*************** + Object currently in edit + ***************/ - $action= ""; - $action.= ""; + if($this->dn){ + /* Set base */ + if ($this->base == ""){ + if ($this->dn == "new"){ + $ui= get_userinfo(); + $this->base= dn2base($ui->dn); + } else { + $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,/", "", $this->dn); + } + } - $divlist = new divlist(); - $divlist->SetHeader(array( - array("string" => " "), - array("string" => _("Blocklist name")." / "._("Department")), - array("string" => _("Actions"), "attach" => "style='border:none'" ))); - - - $divlist->SetSummary(_("This table displays faxblocklists for the selected tree.")); - $divlist->SetEntriesPerPage(20); - - // Defining Links - $linkopen = "%s"; - foreach($this->departments as $key=> $val){ - $field1 = array("string" => "department"); - $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val)); - $field3 = array("string" => " ", "attach" => "style='border:none'"); - $divlist->AddEntry(array($field1,$field2,$field3)); + /* Fill templating stuff */ + $smarty->assign("bases", $this->config->idepartments); + $smarty->assign("base_select", $this->base); + $smarty->assign("types", array(0 => _("send"), 1 => _("receive"))); + if ($this->dn == "new" || preg_match ("/,ou=incoming,/", $this->dn)){ + $smarty->assign("selectmode", ""); + $smarty->assign("mode", ""); + } else { + $smarty->assign("selectmode", "disabled"); + $smarty->assign("mode", "readonly"); + } + foreach(array("cn", "description", "type", "goFaxBlocklist") as $val){ + $smarty->assign("$val", $this->$val); + $smarty->assign("$val"."ACL", chkacl($this->acl, "$val")); } - // User and Template Images - $blockimg = "User"; - $editlink = "%s"; - - foreach($this->blocklists as $key => $val){ - // Generate Array to Add - $display= "[".$val["cn"][0]."]"; - $field1 = array("string" => sprintf($blockimg,$val['dn']),"attach"=>"style='width:20px;align:middle;'"); - $field2 = array("string" => sprintf($editlink,$key,$display),"attach"=>"title='".$val['dn']."'"); - $field3 = array("string" => preg_replace("/%KEY%/", "$key", $action),"attach" => "style='border:none; text-align:right;width:40px'"); - $divlist->AddEntry( array($field1,$field2,$field3)); + /* Lock blocklist type for non new entries */ + if ($this->dn != "new"){ + $smarty->assign('typeACL', "disabled"); } /* Show main page */ - $smarty->assign("blocklistshead", $listhead); - $smarty->assign("blocklists", $divlist->DrawList()); - $smarty->assign("search_image", get_template_path('images/search.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()); - foreach( array("depselect", "entry", "regex", "sendlists", "receivelists") as $type){ - $smarty->assign("$type", $blockfilter[$type]); - } - $smarty->assign("deplist", $this->config->idepartments); - $smarty->assign("alphabet", generate_alphabet()); - $smarty->assign("hint", print_sizelimit_warning()); + return($smarty->fetch (get_template_path('generic.tpl', TRUE))); - return($smarty->fetch(get_template_path('headpage.tpl', TRUE))); - } + }else{ - /* Set base */ - if ($this->base == ""){ - if ($this->dn == "new"){ - $ui= get_userinfo(); - $this->base= dn2base($ui->dn); - } else { - $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,/", "", $this->dn); - } - } + /*************** + Divlist dialog + ***************/ - /* Fill templating stuff */ - $smarty->assign("bases", $this->config->idepartments); - $smarty->assign("base_select", $this->base); - $smarty->assign("types", array(0 => _("send"), 1 => _("receive"))); - if ($this->dn == "new" || preg_match ("/,ou=incoming,/", $this->dn)){ - $smarty->assign("selectmode", ""); - $smarty->assign("mode", ""); - } else { - $smarty->assign("selectmode", "disabled"); - $smarty->assign("mode", "readonly"); - } - foreach(array("cn", "description", "type", "goFaxBlocklist") as $val){ - $smarty->assign("$val", $this->$val); - $smarty->assign("$val"."ACL", chkacl($this->acl, "$val")); - } + /* Display dialog with system list */ + $this->DivListBlocklist->execute(); - /* Lock blocklist type for non new entries */ - if ($this->dn != "new"){ - $smarty->assign('typeACL', "disabled"); + /* Add departments if subsearch is disabled */ + if(!$this->DivListBlocklist->SubSearch){ + $this->DivListBlocklist->AddDepartments($this->DivListBlocklist->selectedBase); + } + $this->reload(); + $this->DivListBlocklist->setEntries($this->blocklists); + return($this->DivListBlocklist->Draw()); } - - /* Show main page */ - return($smarty->fetch (get_template_path('generic.tpl', TRUE))); } + + /* Clear garbage from edited lists */ function clear_fields() { $this->dn= ""; $this->description= ""; $this->cn= ""; - $this->base= ""; + $this->base= $_SESSION['CurrentMainBase']; $this->goFaxBlocklist= array(); - $this->acl= "#none#"; } + + /* Reload the list of known blocklists */ function reload() { - /* Get config */ - $blockfilter= get_global('blockfilter'); - - /* Set base for all searches */ - $base= $blockfilter['depselect']; - $filter= ""; - - /* Regex filter? */ - if ($blockfilter['regex'] != ""){ - $regex= $blockfilter['regex']; - } else { - $regex= "*"; - } - - /* Entry filter? */ - /* Get list of blocklists to be shown */ - if ($blockfilter['sendlists'] == "checked"){ - $filter.= "(objectClass=goFaxSBlock)"; - } - if ($blockfilter['receivelists'] == "checked"){ - $filter.= "(objectClass=goFaxRBlock)"; - } - if ($filter != ""){ - $filter= "(|$filter)"; - } - - if ($blockfilter['entry'] != "" && $blockfilter['entry'] != "*"){ - $filter.= "(|(goFaxSBlocklist=".$blockfilter['entry'].")(goFaxRBlocklist=".$blockfilter['entry']."))"; - } - - /* Generate blocklists */ - $res= get_list($this->ui->subtreeACL, "(&(cn=$regex)$filter)", TRUE, $base, array("*")); - - $this->blocklists=$res; - - /* NEW LIST MANAGMENT - * We also need to search for the departments - * So we are able to navigate like in konquerer - */ - $base2 = preg_replace("/ou=people,/i","",$base); - - $res3 = get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))", - TRUE, $base2, array("ou", "description"), TRUE); - - $this->departments= array(); - $tmp = array(); - foreach ($res3 as $value){ - $tmp[strtolower($value['dn']).$value['dn']]=$value; - } - ksort($tmp); - foreach($tmp as $value){ - if($value["description"][0]!=".."){ - $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]"; - }else{ - $this->departments[$value['dn']]=$value["description"][0]; - } - } - - /* END NEW LIST MANAGMENT - */ + /* Init some vars */ + $filter = $filter2 = ""; + $base = $this->DivListBlocklist->selectedBase; + $Regex = $this->DivListBlocklist->Regex; + $SubSearch = $this->DivListBlocklist->SubSearch; + $ShowSendBocklists = $this->DivListBlocklist->ShowSendBocklists; + $ShowReceiveBlocklists = $this->DivListBlocklist->ShowReceiveBlocklists; + $Flags = GL_SIZELIMIT; + $res = $res2 = array(); + + /* Append subsearch to Flags */ + if($SubSearch){ + $Flags |= GL_SUBSEARCH; + }else{ + $base = "ou=gofax,ou=systems,".$base; + } + + /* Create filter */ + if ($ShowSendBocklists){ + $filter = "(&(objectClass=goFaxSBlock)(|(cn=".$Regex.")(goFaxSBlocklist=".$Regex.")))"; + $res= get_list($filter, $this->ui->subtreeACL, $base,array("*"), $Flags); + } + if ($ShowReceiveBlocklists){ + $filter2= "(&(objectClass=goFaxRBlock)(|(cn=".$Regex.")(goFaxRBlocklist=".$Regex.")))"; + $res2= get_list($filter2, $this->ui->subtreeACL, $base,array("*"), $Flags); + } + + $this->blocklists = array_merge($res,$res2); + + /* appen && sort */ $tmp=array(); foreach($this->blocklists as $tkey => $val ){ $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val; @@ -468,10 +361,13 @@ class blocklist extends plugin reset ($this->blocklists); } + function remove_from_parent() { $ldap= $this->config->get_ldap_link(); $ldap->rmDir($this->dn); + show_ldap_error($ldap->get_error(), _("Removing blocklist object failed")); + $this->clear_fields(); $this->handle_post_events("remove"); } @@ -479,16 +375,16 @@ class blocklist extends plugin /* Save data to object */ function save_object() { + $this->DivListBlocklist->save_object(); plugin::save_object(); - /* Save type, needed to detect objectClass */ - if (isset($_POST['type']) && chkacl($this->acl, "cn") == ""){ - $this->type= $_POST['type']; + if(isset($_POST['base'])){ + $this->base = $_POST['base']; } - - /* Save base, since this is no LDAP attribute */ - if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){ - $this->base= $_POST['base']; + foreach($this->attributes as $attr){ + if(isset($_POST[$attr])){ + $this->$attr = $_POST[$attr]; + } } } @@ -496,7 +392,8 @@ class blocklist extends plugin /* Check values */ function check() { - $message= array(); + /* Call common method to give check the hook */ + $message= plugin::check(); /* Permissions for that base? */ if ($this->base != ""){ @@ -505,10 +402,7 @@ class blocklist extends plugin $new_dn= $this->dn; } - $ui= get_userinfo(); - $acl= get_permissions ($new_dn, $ui->subtreeACL); - $acl= get_module_permission($acl, "blocklist", $new_dn); - if (chkacl($acl, "create") != ""){ + if (chkacl($this->acl, "create") != ""){ $message[]= _("You have no permissions to create a blocklist on this 'Base'."); } @@ -523,8 +417,7 @@ class blocklist extends plugin if ($this->dn == 'new'){ $ldap= $this->config->get_ldap_link(); $ldap->cd ("ou=gofax,ou=systems,".$this->config->current["BASE"]); - $ldap->search ("(&(|(objectClass=goFaxSBlock)(objectClass=goFaxRBlock))". - "(cn=".$this->cn."))", array("cn")); + $ldap->search ("(&(|(objectClass=goFaxSBlock)(objectClass=goFaxRBlock))(cn=".$this->cn."))", array("cn")); if ($ldap->count() != 0){ $message[]= _("Specified name is already used."); } @@ -545,6 +438,7 @@ class blocklist extends plugin { plugin::save(); + /* Type selection */ if ($this->type == 0){ $type= "goFaxSBlock"; @@ -560,14 +454,17 @@ class blocklist extends plugin /* Write back to ldap */ $ldap= $this->config->get_ldap_link(); - $ldap->cd($ldap->getParentDir($this->dn)); - $ldap->search("cn=$this->cn"); + $ldap->cd($this->base); + $ldap->search("cn=$this->cn",array("cn")); + $ldap->cat($this->dn, array('dn')); $a= $ldap->fetch(); + if (count($a)){ if (!isset($this->attrs["$type"."list"])){ $this->attrs["$type"."list"]= array(); } $ldap->cd($this->dn); + $this->cleanup(); $ldap->modify($this->attrs); $this->handle_post_events("modify"); } else { @@ -577,10 +474,11 @@ class blocklist extends plugin $ldap->add($this->attrs); $this->handle_post_events("add"); } - show_ldap_error($ldap->get_error()); + show_ldap_error($ldap->get_error(), _("Saving blocklist object failed")); } + /* Add number */ function addNumber($number) { if (!in_array($number, $this->goFaxBlocklist)){ @@ -589,6 +487,8 @@ class blocklist extends plugin } } + + /* Remove number from list */ function delNumber($numbers) { $tmp= array(); @@ -600,6 +500,8 @@ class blocklist extends plugin $this->goFaxBlocklist= $tmp; } + + /* Delete lock */ function remove_lock() { if (isset($this->dn)){