X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=include%2Fsieve%2Fclass_sieveManagement.inc;h=ba01e0cf3aaa0bbe50a4a26b2d617e99b4afca3a;hb=0d96e184dc6107bff6f32f24b4cda64ddd01c35a;hp=b436808a41a8c2d4552db4c1977efc18987b7bfc;hpb=5fe1220efe6054cb59576949bd8fe2ec77cd7c15;p=gosa.git diff --git a/include/sieve/class_sieveManagement.inc b/include/sieve/class_sieveManagement.inc index b436808a4..ba01e0cf3 100644 --- a/include/sieve/class_sieveManagement.inc +++ b/include/sieve/class_sieveManagement.inc @@ -31,7 +31,7 @@ class sieveManagement extends plugin { var $parent = NULL; var $scripts= array(); - + var $uattrib = "uid"; var $current_script = -1; var $current_handler = NULL; var $script_to_delete =-1; @@ -41,7 +41,7 @@ class sieveManagement extends plugin 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 */ @@ -58,25 +58,27 @@ class sieveManagement extends plugin /* 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 */ - if(!$sieve = $this->get_sieve()){ - print_red( - sprintf( - _("Can't log into SIEVE server. Server says '%s'."), - to_string($this->Sieve_Error))); + /* Get sieve, if this fail abort class initialization */ + if(!$this->sieve_handle = $this->get_sieve()){ return; } /* Get all sieve scripts names */ - if($sieve->sieve_listscripts()){ - if (is_array($sieve->response)){ - foreach($sieve->response as $key => $name){ + if($this->sieve_handle->sieve_listscripts()){ + if (is_array($this->sieve_handle->response)){ + foreach($this->sieve_handle->response as $key => $name){ $data = array(); $data['NAME'] = $name; @@ -93,11 +95,11 @@ class sieveManagement extends plugin /* Get script contents */ foreach($this->scripts as $key => $script){ - $p = new My_Parser; - $sieve->sieve_getscript($script['NAME']); + $p = new My_Parser($this); + $this->sieve_handle->sieve_getscript($script['NAME']); $script = ""; - foreach($sieve->response as $line){ + foreach($this->sieve_handle->response as $line){ $script.=$line; } @@ -108,7 +110,7 @@ class sieveManagement extends plugin $ret = $p->parse($script); if(!$ret){ $this->scripts[$key]['STATUS'] = FALSE; - $this->scripts[$key]['MODE'] = "Source-Only"; + $this->scripts[$key]['MODE'] = "Source"; $this->scripts[$key]['MSG'] = _("Parse failed")."".$p->status_text.""; }else{ $this->scripts[$key]['STATUS'] = TRUE; @@ -118,33 +120,42 @@ class sieveManagement extends plugin $this->scripts[$key]['PARSER'] = $p; $this->scripts[$key]['EDITED'] = FALSE; } - $this->sieve_handle = $sieve; + $this->sieve_handle = $this->sieve_handle; } - /* Return a sieve class hanlde, + /* Return a sieve class handle, * false if login fails */ function get_sieve() { + /* Connect to sieve class and try to get all available sieve scripts */ - $cfg= $this->config->data['SERVERS']['IMAP'][$this->parent->gosaMailServer]; - $this->Sieve_Error = ""; - - /* Log into the mail server */ - $sieve= new sieve( - $cfg["sieve_server"], - $cfg["sieve_port"], - $this->parent->uid, - $cfg["password"], - $cfg["admin"]); - - /* Try to login */ - if (!$sieve->sieve_login()){ - $this->Sieve_Error = $sieve->error_raw; + if(isset($this->config->data['SERVERS']['IMAP'][$this->parent->gosaMailServer])){ + $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->$uattrib, + $cfg["password"], + $cfg["admin"]); + + /* Try to login */ + if (!@$this->sieve_handle->sieve_login()){ + $this->Sieve_Error = $this->sieve_handle->error_raw; + return(FALSE); + } + return($this->sieve_handle); + }else{ + $this->Sieve_Error = sprintf(_("The specified mail server '%s' does not exist within the GOsa configuration."), + $this->parent->gosaMailServer); return(FALSE); } - return($sieve); } @@ -180,26 +191,35 @@ class sieveManagement extends plugin } /* 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.")); } /* 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 alphabetical characters are allowed in script names.")); + } + + $tmp = $this->get_used_script_names(); + if(in_array_ics($name,$tmp)){ + $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; @@ -209,7 +229,7 @@ class sieveManagement extends plugin "stop;"; /* Create a new parser and initialize default values */ - $p = new My_Parser; + $p = new My_Parser($this); $ret = $p->parse($script); $sc['SCRIPT'] = $script; $sc['ORIG_SCRIPT'] = $script; @@ -217,11 +237,11 @@ class sieveManagement extends plugin $sc['MSG'] = ""; if(!$ret){ $sc['STATUS'] = FALSE; - $sc['MODE'] = "Source-Only"; + $sc['MODE'] = "Source"; $sc['MSG'] = _("Parse failed")."".$p->status_text.""; }else{ $sc['STATUS'] = TRUE; - $sc['MODE'] = "Strucktured"; + $sc['MODE'] = "Structured"; $sc['MSG'] = _("Parse successful"); } $sc['PARSER'] = $p; @@ -236,7 +256,6 @@ class sieveManagement extends plugin /* 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__)))); } } @@ -257,42 +276,46 @@ class sieveManagement extends plugin $this->current_script = $script; $this->current_handler = $this->scripts[$script]['PARSER']; + $this->scripts[$script]['SCRIPT_BACKUP'] = $this->scripts[$script]['SCRIPT']; } /* 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; - /* Get sieve */ - if(!$sieve = $this->get_sieve()){ - print_red( - sprintf( - _("Can't log into SIEVE server. Server says '%s'."), - to_string($this->Sieve_Error))); - } + /* We can only activate existing scripts */ + if(!$this->scripts[$script]['IS_NEW']){ - /* Try to activate the given script and update - * class script array. - */ - if(!$this->sieve_handle->sieve_setactivescript($this->scripts[$script]['NAME'])){ - print_red(sprintf(_("Can't activate sieve script on server. Server says '%s'."),to_string($this->sieve_handle->error_raw))); - }else{ - foreach($this->scripts as $key => $data){ - if($key == $script){ - $this->scripts[$key]['ACTIVE'] = TRUE; - }else{ - $this->scripts[$key]['ACTIVE'] = FALSE; + /* Get sieve */ + if(!$this->sieve_handle = $this->get_sieve()){ + print_red( + sprintf( + _("Can't log into SIEVE server. Server says '%s'."), + to_string($this->Sieve_Error))); + } + + /* Try to activate the given script and update + * class script array. + */ + if(!$this->sieve_handle->sieve_setactivescript($this->scripts[$script]['NAME'])){ + print_red(sprintf(_("Can't activate sieve script on server. Server says '%s'."),to_string($this->sieve_handle->error_raw))); + }else{ + foreach($this->scripts as $key => $data){ + if($key == $script){ + $this->scripts[$key]['ACTIVE'] = TRUE; + }else{ + $this->scripts[$key]['ACTIVE'] = FALSE; + } } } } @@ -310,7 +333,7 @@ class sieveManagement extends plugin } /* 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]; @@ -320,14 +343,14 @@ class sieveManagement extends plugin }else{ /* Get sieve */ - if(!$sieve = $this->get_sieve()){ + if(!$this->sieve_handle = $this->get_sieve()){ print_red( sprintf( _("Can't log into SIEVE server. Server says '%s'."), to_string($this->Sieve_Error))); } - if(!$sieve->sieve_deletescript($this->scripts[$this->script_to_delete]['NAME'])){ + if(!$this->sieve_handle->sieve_deletescript($this->scripts[$this->script_to_delete]['NAME'])){ print_red(sprintf(_("Can't remove sieve script from server. Server says '%s'."),to_string($this->sieve_handle->error_raw))); }else{ unset($this->scripts[$this->script_to_delete]); @@ -352,16 +375,21 @@ class sieveManagement extends plugin /* Abort saving */ if(isset($_POST['cancel_sieve_changes'])){ + $tmp = $this->scripts[$this->current_script]['SCRIPT_BACKUP']; + $this->scripts[$this->current_script]['SCRIPT'] = $tmp; + $this->scripts[$this->current_script]['PARSER']->parse($tmp); $this->current_handler = NULL; } /* 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)){ $sc = $this->scripts[$this->current_script]['SCRIPT']; - $p = new My_Parser; + $p = new My_Parser($this); if($p -> parse($sc)){ if($this->scripts[$this->current_script]['MODE'] == "Source-Only"){ @@ -377,7 +405,9 @@ class sieveManagement extends plugin 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)); + } } } @@ -403,7 +433,7 @@ class sieveManagement extends plugin $file = $_FILES['Script_To_Import']; if($file['size'] == 0){ - print_red(_("Specified file seams to empty.")); + print_red(_("Specified file seems to be empty.")); }elseif(!file_exists($file['tmp_name'])){ print_red(_("Upload failed, somehow nothing was uploaded or the temporary file can't be accessed.")); }elseif(!is_readable ($file['tmp_name'])){ @@ -420,6 +450,7 @@ class sieveManagement extends plugin }else{ $this->scripts[$this->current_script]['MODE'] = "Structured"; } + $this->Script_Error = ""; $this->Import_Script = FALSE; } } @@ -480,7 +511,8 @@ class sieveManagement extends plugin /* Element selected */ - if(isset($_POST['element_type']) && isset($element_types[$_POST['element_type']])){ + if(isset($_POST['element_type']) && isset($element_types[$_POST['element_type']]) + || isset($_POST['element_type']) &&in_array($_POST['element_type'],array("sieve_else","sieve_elsif"))){ $this->add_element_type = $_POST['element_type']; } @@ -488,97 +520,59 @@ class sieveManagement extends plugin * the selected position */ if(isset($_POST['select_new_element_type'])){ + if($this->add_new_element_to_current_script($this->add_element_type,$this->add_new_id,$this->add_above_below)){ + $this->add_new_element = FALSE; + }else{ + print_red(_("Failed to add new element.")); + } + } + } - $this->add_new_id; + /* Only display select dialog if it is necessary */ + if($this->add_new_element){ + $smarty = get_smarty(); + + $add_else_elsif = FALSE; - $data = $this->current_handler->tree_->pap; + /* Check if we should add else/elsif to the select box + * or not. We can't add else twice!. + */ + if($this->add_above_below == "below"){ - /* Get index of the element identified by object_id == $this->add_new_id; */ - $index = -1; - foreach($data as $key => $obj){ - if($obj->object_id == $this->add_new_id && $index==-1){ - $index = $key; - } - } - - /* We have found the specified object_id - * and want to detect the next free position - * to insert the new element. + /* Get posistion of the current element */ - if($index != -1){ - if($this->add_above_below == "above"){ - $direction ="up"; - $next_free = $this->current_handler->tree_->_get_next_free_move_slot($index,$direction); - $next_free ++; - }else{ - $direction = "down"; - $next_free = $this->current_handler->tree_->_get_next_free_move_slot($index,$direction); - } - $this->add_new_id = $this->current_handler->tree_->pap[$next_free]->object_id; - } - - /* Create elements we should add */ - $ele[] = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime())); - if($this->add_element_type == "sieve_if"){ - $ele[] = new sieve_block_start(NULL,preg_replace("/[^0-9]/","",microtime())); - $ele[] = new sieve_block_end(NULL,preg_replace("/[^0-9]/","",microtime())); - } - $start = $end = array(); - $found = false; - - /* Add above current element*/ - if($this->add_above_below == "above"){ - foreach($data as $key => $obj){ - if($obj->object_id == $this->add_new_id){ - $found = true; - } - if(!$found){ - $start[] = $obj; - }else{ - $end[] = $obj; - } - } - }else{ - /* Add below current element */ - foreach($data as $key => $obj){ - if(!$found){ - $start[] = $obj; - }else{ - $end[] = $obj; + foreach($this->current_handler->tree_->pap as $key => $obj){ + + if($obj->object_id == $this->add_new_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; + } } - echo $obj->object_id." --> ".$this->add_new_id."
"; - if($obj->object_id == $this->add_new_id){ - $found = true; - echo "Jop"; + + /* 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"); } } - - - /* Only add, if current element could be located */ - if($found){ - $new = array(); - foreach($start as $obj){ - $new[] = $obj; - } - foreach($ele as $el){ - $new[] = $el; - } - foreach($end as $obj){ - $new[] = $obj; - } - $data= $new; - $this->current_handler->tree_->pap = $data; - $this->add_new_element = FALSE; - }else{ - print_red(_("Something went wrong while adding a new entry.")); - } } - } - /* Only display select dialog if it is necessary */ - if($this->add_new_element){ - $smarty = get_smarty(); $smarty->assign("element_types",$element_types ); $smarty->assign("element_type",$this->add_element_type); $str = $smarty->fetch(get_template_path("templates/add_element.tpl",TRUE,dirname(__FILE__))); @@ -644,50 +638,281 @@ class sieveManagement extends plugin $field1 = array("string" => " ", "attach" => "style='width:20px;'"); if($active){ - $field1 = array("string" => ""._("Active")."", + $field1 = array("string" => ""._("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" => ""._("Edited")."", - "attach" => "style='width:30px;'"); + if($this->parent->acl_is_writeable("sieveManagement")){ + $del = ""; }else{ - $field5 = array("string" => "", - "attach" => "style='width:30px;'"); + $del = " "; } - if($active){ - $field6 = array("string" => " ". - "". - ""); + if($active || $script['IS_NEW'] || !$this->parent->acl_is_writeable("sieveManagement")){ + $activate = " "; }else{ - $field6 = array("string" => "". - "". - ""); + $activate = ""; } - $List ->AddEntry(array($field1,$field2,$field3,$field4,$field5,$field6)); + + $field6 = array("string" => $activate."".$del, + "attach" => "style='border-right:0px; width:70px;'"); + $List->AddEntry(array($field1,$field2,$field3,$field4,$field6)); } - - $display ="

Sieve script management

"; - $display .= _("Be careful. All your changes will be saved directly to sieve, if you use the save button below."); - $display .= "
"; - $display .= $List->DrawList(); - - $display .= "

\n"; - $display .= "\n"; - $display .= " \n"; - $display .= "\n"; - $display .= "

"; - return($display);; + + $List->SetHeight(400); + + /* 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__)))); } + + /* Add a new element to the currently opened script editor. + * The insert position is specified by + */ + function add_new_element_to_current_script($type,$id,$position) + { + /* Test given data */ + if(!in_array_ics($position,array("above","below"))){ + trigger_error("Can't add new element with \$position=".$position.". Only 'above','below' are allowed here."); + return(FALSE); + } + if(!is_numeric($id)){ + trigger_error("Can't add new element, given id is not numeric."); + return(FALSE); + } + $tmp = get_declared_classes(); + if(!in_array($type,$tmp)){ + 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"){ + trigger_error("Can't add new element, there is no valid script editor opened."); + 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 + */ + $parent = $this->current_handler->tree_; + if($this->add_element_type == "sieve_if"){ + $ele[] = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime()),$parent); + $ele[] = new sieve_block_start(NULL,preg_replace("/[^0-9]/","",microtime()),$parent); + $ele[] = new sieve_block_end(NULL,preg_replace("/[^0-9]/","",microtime()),$parent); + }elseif($this->add_element_type == "sieve_else"){ + $ele[] = new sieve_block_end(NULL,preg_replace("/[^0-9]/","",microtime()),$parent); + $ele[] = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime()),$parent); + $ele[] = new sieve_block_start(NULL,preg_replace("/[^0-9]/","",microtime()),$parent); + }elseif($this->add_element_type == "sieve_elsif"){ + $ele[] = new sieve_block_end(NULL,preg_replace("/[^0-9]/","",microtime()),$parent); + $ele[] = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime()),$parent); + $ele[] = new sieve_block_start(NULL,preg_replace("/[^0-9]/","",microtime()),$parent); + }else{ + $ele[] = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime()),$parent); + } + + /* Get index of the element identified by object_id == $id; + */ + $index = -1; + $data = $this->current_handler->tree_->pap; + foreach($data as $key => $obj){ + if($obj->object_id == $id && $index==-1){ + $index = $key; + } + } + + /* Tell to user that we couldn't find the given object + * so we can't add an element. + */ + if($index == -1 ){ + trigger_error("Can't add new element, specified \$id=".$id." could not be found in object tree."); + return(FALSE); + } + + /* We have found the specified object_id + * and want to detect the next free position + * to insert the new element. + */ + if($position == "above"){ + $direction ="up"; + $next_free = $this->current_handler->tree_->_get_next_free_move_slot($index,$direction,TRUE); + }else{ + $direction = "down"; + $next_free = $this->current_handler->tree_->_get_next_free_move_slot($index,$direction,TRUE); + } + /* This is extremly necessary, cause some objects + * updates the tree objects ... Somehow i should change this ... + */ + $data = $this->current_handler->tree_->pap; + $start = $end = array(); + + if($position == "above"){ + $start = array_slice($data,0,$next_free); + $end = array_slice($data,$next_free); + }else{ + $start = array_slice($data,0,$next_free+1); + $end = array_slice($data,$next_free+1); + } + + $new = array(); + foreach($start as $obj){ + $new[] = $obj; + } + foreach($ele as $el){ + $new[] = $el; + } + foreach($end as $obj){ + $new[] = $obj; + } + $data= $new; + $this->current_handler->tree_->pap = $data; + return(TRUE); + } + + + function save_object() { 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; @@ -696,15 +921,19 @@ class sieveManagement extends plugin 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){ @@ -726,13 +955,14 @@ class sieveManagement extends plugin * if we are currently in a subdialog */ + $this->current_handler->save_object(); $Mode = $this->scripts[$this->current_script]['MODE']; $skip_mode_change = false; if(in_array($Mode,array("Source-Only","Source"))){ if(isset($_POST['script_contents'])){ $sc = stripslashes($_POST['script_contents']); $this->scripts[$this->current_script]['SCRIPT'] = $sc; - $p = new My_Parser; + $p = new My_Parser($this); if($p -> parse($sc)){ $this->Script_Error = ""; } else { @@ -744,7 +974,7 @@ class sieveManagement extends plugin if(in_array($Mode,array("Structured"))){ $sc = $this->current_handler->get_sieve_script(); $this->scripts[$this->current_script]['SCRIPT'] = $sc; - $p = new My_Parser; + $p = new My_Parser($this); if($p -> parse($sc)){ $this->Script_Error = ""; } else { @@ -766,7 +996,7 @@ class sieveManagement extends plugin if($old_mode != $new_mode){ $sc = $this->scripts[$this->current_script]['SCRIPT']; - $p = new My_Parser; + $p = new My_Parser($this); if($p -> parse($sc)){ $this->current_handler->parse($sc); @@ -777,25 +1007,29 @@ class sieveManagement extends plugin } } } - $this->current_handler->save_object(); } } - - function save() + + function get_used_script_names() { - /* Connect to sieve class and try to get all available sieve scripts */ - $cfg= $this->config->data['SERVERS']['IMAP'][$this->parent->gosaMailServer]; + $ret = array(); + foreach($this->scripts as $script){ + $ret[] = $script['NAME']; + } + return($ret); + } - $this->sieve_handle= - new sieve( $cfg["sieve_server"], - $cfg["sieve_port"], - $this->parent->mail, - $cfg["password"], - $cfg["admin"]); - if (!$this->sieve_handle->sieve_login()){ - print_red(sprintf(_("Can't log into SIEVE server. Server says '%s'."),to_string($this->sieve_handle->error_raw))); + + function save() + { + /* Get sieve */ + 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; } @@ -804,7 +1038,7 @@ class sieveManagement extends plugin foreach($this->scripts as $key => $script){ if($script['EDITED']){ $data = $this->scripts[$key]['SCRIPT']; - if(!$this->sieve_handle->sieve_sendscript($script['NAME'], $data)){ + if(!$this->sieve_handle->sieve_sendscript($script['NAME'], addcslashes ($data,"\\"))){ gosa_log("Failed to save sieve script named '".$script['NAME']."': ".to_string($this->sieve_handle->error_raw)); $everything_went_fine = FALSE; print_red(to_string($this->sieve_handle->error_raw));