index d5701e3bb87e96683df4ecd2b3bd8aec0621c8ef..bc8936b37e213b6fcf39e5f22e767be0ec88f527 100644 (file)
{
var $parent = NULL;
var $scripts= array();
-
+ var $uattrib = "uid";
var $current_script = -1;
var $current_handler = NULL;
var $script_to_delete =-1;
var $create_script = FALSE;
/* To add new elements we need to know
- * Where to the element -> add_new_id
+ * Where to add the element -> add_new_id
* Whould we add above or below this id -> add_above_below
* What kind of element should we add -> add_element_type
*/
/* Initialize the class and load all sieve scripts
* try to parse them and display errors
*/
- function sieveManagement($config,$dn,$parent)
+ function sieveManagement($config,$dn,$parent,$uattrib)
{
+ /* Check given parameter */
+ if(!isset($parent->$uattrib)){
+ trigger_error("Sieve Management implementation error. Parameter 4 must be part of the given parent element.");
+ }
+
+ $this->uattrib = $uattrib;
$this->parent = $parent;
plugin::plugin($config,$dn);
- /* Get sieve */
+ /* Get sieve, if this fail abort class initialization */
if(!$this->sieve_handle = $this->get_sieve()){
- print_red(
- sprintf(
- _("Can't log into SIEVE server. Server says '%s'."),
- to_string($this->Sieve_Error)));
return;
}
}
- /* Return a sieve class hanlde,
+ /* Return a sieve class handle,
* false if login fails
*/
function get_sieve()
$cfg= $this->config->data['SERVERS']['IMAP'][$this->parent->gosaMailServer];
$this->Sieve_Error = "";
+ $uattrib = $this->uattrib;
+
/* Log into the mail server */
$this->sieve_handle= new sieve(
$cfg["sieve_server"],
$cfg["sieve_port"],
- $this->parent->uid,
+ $this->parent->$uattrib,
$cfg["password"],
$cfg["admin"]);
/* Try to login */
- if (!$this->sieve_handle->sieve_login()){
+ if (!@$this->sieve_handle->sieve_login()){
$this->Sieve_Error = $this->sieve_handle->error_raw;
return(FALSE);
}
}
/* Check given name */
- $err = "";
+ $err = false;
/* Is given name in lower case characters ? */
if(isset($_POST['create_script_save'])){
if(!strlen($name)){
- $err = _("You should specify a name for your new script.");
+ $err =true;
+ print_red(_("You should specify a name for your new script."));
}
/* Is given name in lower case characters ? */
if($name != strtolower($name)){
- $err = _("Only lower case names are allowed here.");
+ $err =true;
+ print_red(_("Only lower case names are allowed here."));
}
/* Only chars are allowed here */
if(preg_match("/[^a-z]/i",$name)){
- $err = _("Only a-z are allowed in script names.");
+ $err =true;
+ print_red(_("Only a-z are allowed in script names."));
}
$tmp = $this->get_used_script_names();
if(in_array_ics($name,$tmp)){
- $err =_("The specified name is already in use.");
+ $err =true;
+ print_red(_("The specified name is already in use."));
}
}
/* Create script if everything is ok */
- if($this->create_script && isset($_POST['create_script_save']) && $err == "" ){
+ if($this->create_script && isset($_POST['create_script_save']) && !$err){
/* Close dialog */
$this->create_script = FALSE;
/* Display dialog to enter new script name */
$smarty = get_smarty();
$smarty->assign("NewScriptName",$name);
- $smarty->assign("Error",$err);
return($smarty->fetch(get_template_path("templates/create_script.tpl",TRUE,dirname(__FILE__))));
}
}
}
/* remove script requested */
- if(preg_match("/^delscript_/",$name) && $once && !$this->current_handler){
+ if($this->parent->acl_is_writeable("sieveManagement") && preg_match("/^delscript_/",$name) && $once && !$this->current_handler){
$script = preg_replace("/^delscript_/","",$name);
$script = preg_replace("/_(x|y)/","",$script);
$once = FALSE;
-
$this->script_to_delete = $script;
}
/* Activate script */
- if(preg_match("/^active_script_/",$name) && $once && !$this->current_handler){
+ if($this->parent->acl_is_writeable("sieveManagement") && preg_match("/^active_script_/",$name) && $once && !$this->current_handler){
$script = preg_replace("/^active_script_/","",$name);
$script = preg_replace("/_(x|y)/","",$script);
$once = FALSE;
}
/* Remove confirmed */
- if(isset($_POST['delete_script_confirm'])){
+ if($this->parent->acl_is_writeable("sieveManagement") && isset($_POST['delete_script_confirm'])){
$script = $this->scripts[$this->script_to_delete];
}
/* Save currently edited sieve script. */
- if(isset($_POST['save_sieve_changes'])){
+ if($this->parent->acl_is_writeable("sieveManagement") &&
+ isset($_POST['save_sieve_changes']) &&
+ is_object($this->current_handler)){
$chk = $this->current_handler->check();
if(!count($chk)){
print_red($p->status_text);;
}
}else{
- print_red(_("Please fix all errors before saving."));
+ foreach($chk as $msgs){
+ print_red(sprintf(_("Please fix all errors before saving. Last error was : %s"),$msgs));
+ }
}
}
}else{
$this->scripts[$this->current_script]['MODE'] = "Structured";
}
+ $this->Script_Error = "";
$this->Import_Script = FALSE;
}
}
$field1 = array("string" => " ",
"attach" => "style='width:20px;'");
if($active){
- $field1 = array("string" => "<img src='images/true.png' alt='"._("Active")."'>",
+ $field1 = array("string" => "<img src='images/true.png' alt='"._("Active")."'
+ title='"._("This script is marked as active")."'>",
"attach" => "style='width:20px;'");
}
$field2 = array("string" => $script['NAME']);
$field3 = array("string" => $script['MSG']);
- $field4 = array("string" => _("Script length")." : ".strlen($script['SCRIPT']));
+ $field4 = array("string" => _("Script length").": ".strlen($script['SCRIPT']));
- if($edited){
- $field5 = array("string" => "<img src='images/fai_new_hook.png' alt='"._("Edited")."'>",
- "attach" => "style='width:30px;'");
+ if($this->parent->acl_is_writeable("sieveManagement")){
+ $del = "<input type='image' name='delscript_".$key."' src='images/edittrash.png'
+ title='"._("Remove script")."'>";
}else{
- $field5 = array("string" => "",
- "attach" => "style='width:30px;'");
+ $del = "<img src='images/empty' alt=' '>";
}
- if($active || $script['IS_NEW']){
- $field6 = array("string" => "<img src='images/empty.png' alt=' '>".
- "<input type='image' name='editscript_".$key."' src='images/edit.png'>".
- "<input type='image' name='delscript_".$key."' src='images/edittrash.png'>");
+ if($active || $script['IS_NEW'] || !$this->parent->acl_is_writeable("sieveManagement")){
+ $activate = "<img src='images/empty' alt=' '>";
}else{
- $field6 = array("string" => "<input type='image' name='active_script_".$key."' src='images/true.png'>".
- "<input type='image' name='editscript_".$key."' src='images/edit.png'>".
- "<input type='image' name='delscript_".$key."' src='images/edittrash.png'>");
+ $activate = "<input type='image' name='active_script_".$key."' src='images/true.png'
+ title='"._("Activate script")."'>";
}
- $List ->AddEntry(array($field1,$field2,$field3,$field4,$field5,$field6));
+
+ $field6 = array("string" => $activate."<input type='image' name='editscript_".$key."' src='images/edit.png'
+ title='"._("Edit script")."'>".$del,
+ "attach" => "style='border-right:0px; width:70px;'");
+ $List->AddEntry(array($field1,$field2,$field3,$field4,$field6));
}
-
- $display ="<h2>Sieve script management</h2>";
- $display .= _("Be careful. All your changes will be saved directly to sieve, if you use the save button below.");
- $display .= "<br><input type='submit' name='create_new_script' value='"._("Create new script")."'>";
- $display .= $List->DrawList();
-
- $display .= "<p style=\"text-align:right\">\n";
- $display .= "<input type=submit name=\"sieve_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
- $display .= " \n";
- $display .= "<input type=submit name=\"sieve_cancel\" value=\""._("Cancel")."\">\n";
- $display .= "</p>";
- return($display);;
+
+ /* If the uattrib is empty (Attribute to use for authentification with sieve)
+ * Display a message that the connection can't be established.
+ */
+ $uattrib = $this->uattrib;
+ $smarty = get_smarty();
+
+ if(!$this->get_sieve()){
+ $smarty->assign("Sieve_Error",sprintf(
+ _("Can't log into SIEVE server. Server says '%s'."),
+ to_string($this->Sieve_Error)));
+ }else{
+ $smarty->assign("Sieve_Error","");
+ }
+
+ $smarty->assign("uattrib_empty",empty($this->parent->$uattrib));
+ $smarty->assign("List",$List->DrawList());
+ return($smarty->fetch(get_template_path("templates/management.tpl",TRUE,dirname(__FILE__))));
}
}
$tmp = get_declared_classes();
if(!in_array($type,$tmp)){
- trigger_error("Can't add new element, given \$class=".$class." does not exists.");
+ if(!empty($type)){
+ trigger_error("Can't add new element, given \$class=".$class." does not exists.");
+ }
return(FALSE);
}
if(!is_object($this->current_handler) || get_class($this->current_handler) != "My_Parser"){
return(FALSE);
}
+ /* These element types are allowed to be added here */
+ $element_types= array(
+ "sieve_keep" => _("Keep"),
+ "sieve_comment" => _("Comment"),
+ "sieve_fileinto" => _("File into"),
+ "sieve_keep" => _("Keep"),
+ "sieve_discard" => _("Discard"),
+ "sieve_redirect" => _("Redirect"),
+ "sieve_reject" => _("Reject"),
+ "sieve_require" => _("Require"),
+ "sieve_stop" => _("Stop"),
+ "sieve_vacation" => _("Vacation message"),
+ "sieve_if" => _("If"));
+
+ /* Check if we should add else/elsif to the select box
+ * or not. We can't add else twice!.
+ */
+
+ /* Get posistion of the current element
+ */
+ foreach($this->current_handler->tree_->pap as $key => $obj){
+
+ if($obj->object_id == $id && in_array(get_class($obj),array("sieve_if","sieve_elsif"))){
+
+ /* Get block start/end */
+ $end_id = $this->current_handler->tree_->get_block_end($key);
+ $else_found = FALSE;
+ $elsif_found = FALSE;
+
+ /* Check if there is already an else in this block
+ */
+ for($i = $key ; $i < $end_id ; $i ++){
+ if(get_class($this->current_handler->tree_->pap[$i]) == "sieve_else"){
+ $else_found = TRUE;
+ }
+ if(get_class($this->current_handler->tree_->pap[$i]) == "sieve_elsif"){
+ $elsif_found = TRUE;
+ }
+ }
+
+ if($this->add_above_below == "below"){
+
+ /* Only allow adding 'else' if there is currently
+ * no 'else' statement. And don't allow adding
+ * 'else' before 'elseif'
+ */
+ if(!$else_found && (!(get_class($obj) == "sieve_if" && $elsif_found))){
+ $element_types['sieve_else'] = _("Else");
+ }
+ $element_types['sieve_elsif'] = _("Else if");
+ }else{
+
+ /* Allow adding elsif above elsif */
+ if(in_array(get_class($obj),array("sieve_elsif"))){
+ $element_types['sieve_elsif'] = _("Else if");
+ }
+ }
+ }
+ }
+
+ if(!isset($element_types[$type])){
+ print_red(sprintf(_("Can't add the specified element at the given position.")));
+ return;
+ }
+
+
/* Create elements we should add
* -Some element require also surrounding block elements
*/
{
if($this->current_handler){
+ if(isset($_GET['Add_Object_Top_ID'])){
+ $this->add_new_element = TRUE;
+ $this->add_new_id = $_GET['Add_Object_Top_ID'];
+ $this->add_above_below = "above";
+ }
+
+ if(isset($_GET['Add_Object_Bottom_ID'])){
+ $this->add_new_element = TRUE;
+ $this->add_new_id = $_GET['Add_Object_Bottom_ID'];
+ $this->add_above_below = "below";
+ }
+
+ if(isset($_GET['Remove_Object_ID'])){
+ $found_id = -1;
+ foreach($this->current_handler->tree_->pap as $key => $element){
+ if($element->object_id == $_GET['Remove_Object_ID']){
+ $found_id = $key;
+ }
+ }
+ if($found_id != -1 ){
+ $this->current_handler->tree_->remove_object($found_id);
+ }
+ }
+
+ if(isset($_GET['Move_Up_Object_ID'])){
+ $found_id = -1;
+ foreach($this->current_handler->tree_->pap as $key => $element){
+ if($element->object_id == $_GET['Move_Up_Object_ID']){
+ $found_id = $key;
+ }
+ }
+ if($found_id != -1 ){
+ $this->current_handler->tree_->move_up_down($found_id,"up");
+ }
+ }
+
+ if(isset($_GET['Move_Down_Object_ID'])){
+ $found_id = -1;
+ foreach($this->current_handler->tree_->pap as $key => $element){
+ if($element->object_id == $_GET['Move_Down_Object_ID']){
+ $found_id = $key;
+ }
+ }
+ if($found_id != -1 ){
+ $this->current_handler->tree_->move_up_down($found_id,"down");
+ }
+ }
+
+
/* Check if there is an add object requested
*/
$data = $this->current_handler->tree_->pap;
foreach($data as $key => $obj){
if(isset($obj->object_id) && preg_match("/^Add_Object_Top_".$obj->object_id."_/",$name) && $once){
$once = FALSE;
- $this->add_new_element = TRUE;
+ $this->add_element_type = $_POST['element_type_'.$obj->object_id];
+ $this->add_new_element = FALSE;
$this->add_new_id = $obj->object_id;
$this->add_above_below = "above";
+ $this->add_new_element_to_current_script($this->add_element_type,$this->add_new_id,$this->add_above_below);
}
if(isset($obj->object_id) && preg_match("/^Add_Object_Bottom_".$obj->object_id."_/",$name) && $once){
$once = FALSE;
- $this->add_new_element = TRUE;
+ $this->add_element_type = $_POST['element_type_'.$obj->object_id];
+ $this->add_new_element = FALSE;
$this->add_new_id = $obj->object_id;
$this->add_above_below = "below";
+ $this->add_new_element_to_current_script($this->add_element_type,$this->add_new_id,$this->add_above_below);
}
if(isset($obj->object_id) && preg_match("/^Remove_Object_".$obj->object_id."_/",$name) && $once){
sprintf(
_("Can't log into SIEVE server. Server says '%s'."),
to_string($this->Sieve_Error)));
+ return;
}
$everything_went_fine = TRUE;