summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7b04c4b)
raw | patch | inline | side by side (parent: 7b04c4b)
author | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Fri, 16 Mar 2007 08:07:46 +0000 (08:07 +0000) | ||
committer | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Fri, 16 Mar 2007 08:07:46 +0000 (08:07 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@5792 594d385d-05f5-0310-b6e9-bd551577e9d8
index 224a8e38abff0c04402ddd060477d7b8146210f1..369d26c3e0c4a40550a6d50ba066f148c299983f 100644 (file)
var $add_type = "top";
var $add_element_type = "";
- var $Mode = "Structured";
-
function execute()
{
- foreach($_POST as $name => $value){
- if(preg_match("/Add_Test_Object_/",$name)) {
- $name = preg_replace("/Add_Test_Object_/","",$name);
- $name = preg_replace("/_(x|y)$/","",$name);
-
- $test_types_to_add = array(
- "address" =>_("Address"),
- "header" =>_("Header"),
- "envelope"=>_("Envelope"),
- "size" =>_("Size"),
- "exists" =>_("Exists"),
- "allof" =>_("All of"),
- "anyof" =>_("Any of"),
- "true" =>_("True"),
- "false" =>_("False"));
-
- $smarty = get_smarty();
- $smarty->assign("ID",$name);
- $smarty->assign("test_types_to_add",$test_types_to_add);
- $ret = $smarty->fetch(get_template_path("templates/select_test_type.tpl",TRUE,dirname(__FILE__)));
- return($ret);
- }
- }
-
return($this->dump());
}
* Handle new elements
**************/
- if(isset($_POST['select_new_element_type_cancel'])){
- $this->add_new = FALSE;
- }
-
- if($this->add_new){
-
- $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"));
-
-
- /* Element selected */
- if(isset($_POST['element_type']) && isset($element_types[$_POST['element_type']])){
- $this->add_element_type = $_POST['element_type'];
- }
-
- /* Create new element and add it at the selected position */
- if(isset($_POST['select_new_element_type'])){
-
- $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_type == "top"){
- foreach($this->pap 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($this->pap as $key => $obj){
- if(!$found){
- $start[] = $obj;
- }else{
- $end[] = $obj;
- }
- if($obj->object_id == $this->add_new_id){
- $found = true;
- }
- }
- }
-
- /* 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;
- }
- $this->pap = $new;
- $this->add_new = FALSE;
- }else{
- print_red(_("Something went wrong while adding a new entry."));
- }
- }
-
- }
-
- /* Only display select dialog if it is necessary */
- if($this->add_new){
- $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__)));
- return($str);
- }
-
/* Only parse the tokens once */
if(!count($this->pap)){
$this->dump_ = "";
$this->pap[$key]->save_object();
}
}
-
- $once = TRUE;
- foreach($_POST as $name => $value){
-
- if(isset($obj->object_id) && preg_match("/^Remove_Object_".$obj->object_id."_/",$name) && $once){
- $once = FALSE;
- $this->remove_object($key);
- }
- if(isset($obj->object_id) && preg_match("/^Move_Up_Object_".$obj->object_id."_/",$name) && $once){
- $this->move_up_down($key,"up");
- $once = FALSE;
- }
- if(isset($obj->object_id) && preg_match("/^Move_Down_Object_".$obj->object_id."_/",$name) && $once){
- $this->move_up_down($key,"down");
- $once = FALSE;
- }
- if(isset($obj->object_id) && preg_match("/^Add_Object_Top_".$obj->object_id."_/",$name) && $once){
- $this->add_new_object($obj->object_id,"top");
- $once = FALSE;
- }
- if(isset($obj->object_id) && preg_match("/^Add_Object_Bottom_".$obj->object_id."_/",$name) && $once){
- $this->add_new_object($obj->object_id,"bottom");
- $once = FALSE;
- }
- }
}
}
- /* Add a new object at the given position */
- function add_new_object($id,$top_bottom = "bottom")
- {
- $this->add_new = TRUE;
- $this->add_new_id = $id;
- $this->add_type = $top_bottom;
- }
-
-
/* Remove the object at the given position */
function remove_object($key_id)
{
index 1663fdf4082e6a170803552d1a6024f97f610921..1e4f6829f73e71e83093dbf245f9333e9b3b63d6 100644 (file)
$parsed = $this->_parsed;
}
+
+ if(!is_array($parsed)){
+ return;
+ }
+
/* Walk through all elements */
foreach($parsed as $key => $data){
diff --git a/include/sieve/class_sieveElement_Vacation.inc b/include/sieve/class_sieveElement_Vacation.inc
index 1809cad8b321b5db8f6c7b95c2f2e68b1355c266..6854b1862e5c74ff4c4e6a261770444bf3e17217 100644 (file)
function sieve_vacation($data,$object_id)
{
+
+ $this->object_id = $object_id;
/* Usage: vacation [":days" number] [":subject" string]
[":from" string] [":addresses" string-list]
[":mime"] [":handle" string] <reason: string> */
index 99237f5394fe07df8fcb41b3016574a41766172a..dca53556f94dfa001ca95b5163e617976b77ab15 100644 (file)
var $current_handler = NULL;
var $script_to_delete =-1;
var $sieve_handle = NULL;
-
+ var $Script_Error = "";
var $create_script = FALSE;
+ /* To add new elements we need to know
+ * Where to 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
+ */
+ var $add_new_element = FALSE;
+ var $add_new_id = -1;
+ var $add_above_below = "below";
+ var $add_element_type = "sieve_comment";
+
+
/* Initialize the class and load all sieve scripts
* try to parse them and display errors
*/
$script.=$line;
}
+ $this->scripts[$key]['IS_NEW'] = FALSE;;
$this->scripts[$key]['SCRIPT'] = $script;
$this->scripts[$key]['ORIG_SCRIPT'] = $script;
$this->scripts[$key]['MSG'] = "";
*/
function execute()
{
+ /***************
+ * Create a new Script
+ ***************/
+
+ /* Force opening the add script dialog */
if(isset($_POST['create_new_script'])){
$this->create_script = TRUE;
}
+ /* Close add script dialog, without adding a new one */
if(isset($_POST['create_script_cancel'])){
$this->create_script = FALSE;
}
+ /* Display create script dialog
+ * handle posts, display warnings if specified
+ * name is not useable.
+ * Create a new script with given name
+ */
if($this->create_script){
- $smarty = get_smarty();
+ /* Set initial name or used posted name if available */
$name = "";
if(isset($_POST['NewScriptName'])){
- $name = $_POST['NewScriptName'];
+ $name = trim($_POST['NewScriptName']);
}
-
+
+ /* Check given name */
$err = "";
- if($name != strtolower($name)){
- $err = _("Only lower case names are allowed here.");
- }
-
- if(preg_match("/[^a-z]/i",$name)){
- $err = _("Only a-z are allowed in script names.");
+
+ /* 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.");
+ }
+ /* Is given name in lower case characters ? */
+ if($name != strtolower($name)){
+ $err = _("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.");
+ }
}
+ /* Create script if everything is ok */
if($this->create_script && isset($_POST['create_script_save']) && $err == "" ){
+
+ /* Close dialog */
$this->create_script = FALSE;
+ /* Script contents to use */
$script = "/*New script */".
"stop;";
- $p = new My_Parser;
+ /* Create a new parser and initialize default values */
+ $p = new My_Parser;
+ $ret = $p->parse($script);
$sc['SCRIPT'] = $script;
$sc['ORIG_SCRIPT'] = $script;
+ $sc['IS_NEW'] = TRUE;
$sc['MSG'] = "";
-
- $ret = $p->parse($script);
if(!$ret){
$sc['STATUS'] = FALSE;
$sc['MODE'] = "Source-Only";
$sc['EDITED'] = TRUE;
$sc['ACTIVE'] = FALSE;
$sc['NAME'] = $name;
+
+ /* Add script */
$this->scripts[$name] = $sc;
}else{
+
+ /* 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__))));
}
}
+
+ /*************
+ * Handle several posts
+ *************/
+
$once = TRUE;
foreach($_POST as $name => $value){
+
+ /* Edit script requested */
if(preg_match("/^editscript_/",$name) && $once && !$this->current_handler){
$script = preg_replace("/^editscript_/","",$name);
$script = preg_replace("/_(x|y)/","",$script);
$this->current_script = $script;
$this->current_handler = $this->scripts[$script]['PARSER'];
}
+
+ /* remove script requested */
if(preg_match("/^delscript_/",$name) && $once && !$this->current_handler){
$script = preg_replace("/^delscript_/","",$name);
$script = preg_replace("/_(x|y)/","",$script);
$this->script_to_delete = $script;
}
+
+ /* Activate script */
if(preg_match("/^active_script_/",$name) && $once && !$this->current_handler){
$script = preg_replace("/^active_script_/","",$name);
$script = preg_replace("/_(x|y)/","",$script);
return;
}
+ /* 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{
}
}
+
+ /*************
+ * Remove script handling
+ *************/
+
+ /* Remove aborted */
if(isset($_POST['delete_cancel'])){
$this->script_to_delete = -1;
}
+ /* Remove confirmed */
if(isset($_POST['delete_script_confirm'])){
- /* Connect to sieve class and try to get all available sieve scripts */
- $cfg= $this->config->data['SERVERS']['IMAP'][$this->parent->gosaMailServer];
- $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)));
- return;
- }
+ $script = $this->scripts[$this->script_to_delete];
- 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{
+ /* Just remove from array if it is a new script */
+ if($script['IS_NEW']){
unset($this->scripts[$this->script_to_delete]);
+ }else{
+
+ /* Connect to sieve class and try to get all available sieve scripts */
+ $cfg= $this->config->data['SERVERS']['IMAP'][$this->parent->gosaMailServer];
+ $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)));
+ return;
+ }
+
+ 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]);
+ }
}
$this->script_to_delete = -1;
}
+ /* Display confirm dialog */
if($this->script_to_delete != -1){
$smarty = get_smarty();
$smarty->assign("Warning",
sprintf(_("You are going to remove the sieve script '%s' from your mail server."),
$this->scripts[$this->script_to_delete]['NAME']));
-
return($smarty->fetch(get_template_path("templates/remove_script.tpl",TRUE,dirname(__FILE__))));
}
+
+ /**************
+ * Save script changes
+ **************/
+
/* Abort saving */
if(isset($_POST['cancel_sieve_changes'])){
$this->current_handler = NULL;
*/
if($this->current_handler){
+ /****
+ * Add new element to ui
+ ****/
+
+ /* Abort add dialog */
+ if(isset($_POST['select_new_element_type_cancel'])){
+ $this->add_new_element = FALSE;
+ }
+
+ /* Add a new element */
+ if($this->add_new_element){
+
+ $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"));
+
+
+ /* Element selected */
+ if(isset($_POST['element_type']) && isset($element_types[$_POST['element_type']])){
+ $this->add_element_type = $_POST['element_type'];
+ }
+
+ /* Create new element and add it to
+ * the selected position
+ */
+ if(isset($_POST['select_new_element_type'])){
+
+ /* 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;
+ $data = $this->current_handler->tree_->pap;
+
+ /* 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;
+ }
+ if($obj->object_id == $this->add_new_id){
+ $found = true;
+ }
+ }
+ }
+
+ /* 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__)));
+ return($str);
+ }
+
+
+
+ /****************
+ * Handle test posts
+ ****************/
+
+ /* handle some special posts from test elements
+ */
+ foreach($_POST as $name => $value){
+ if(preg_match("/^Add_Test_Object_/",$name)) {
+ $name = preg_replace("/^Add_Test_Object_/","",$name);
+ $name = preg_replace("/_(x|y)$/","",$name);
+
+ $test_types_to_add = array(
+ "address" =>_("Address"),
+ "header" =>_("Header"),
+ "envelope"=>_("Envelope"),
+ "size" =>_("Size"),
+ "exists" =>_("Exists"),
+ "allof" =>_("All of"),
+ "anyof" =>_("Any of"),
+ "true" =>_("True"),
+ "false" =>_("False"));
+
+ $smarty = get_smarty();
+ $smarty->assign("ID",$name);
+ $smarty->assign("test_types_to_add",$test_types_to_add);
+ $ret = $smarty->fetch(get_template_path("templates/select_test_type.tpl",TRUE,dirname(__FILE__)));
+ return($ret);
+ }
+ }
+
$current = $this->scripts[$this->current_script];
/* Create html results */
}else{
$smarty->assign("Contents",$current['SCRIPT']);
}
+ $smarty->assign("Script_Error",$this->Script_Error);
$ret = $smarty->fetch(get_template_path("templates/edit_frame_base.tpl",TRUE,dirname(__FILE__)));
return($ret);
}
{
if($this->current_handler){
- $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']);
+ /* Check if there is an add object requested
+ */
+ $data = $this->current_handler->tree_->pap;
+ $once = TRUE;
+ foreach($_POST as $name => $value){
+ 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_new_id = $obj->object_id;
+ $this->add_above_below = "above";
+ }
+ if(isset($obj->object_id) && preg_match("/^Add_Object_Bottom_".$obj->object_id."_/",$name) && $once){
+ $once = FALSE;
+ $this->add_new_element = TRUE;
+ $this->add_new_id = $obj->object_id;
+ $this->add_above_below = "below";
+ }
+
+ if(isset($obj->object_id) && preg_match("/^Remove_Object_".$obj->object_id."_/",$name) && $once){
+ $once = FALSE;
+ $this->current_handler->tree_->remove_object($key);
+ }
+ if(isset($obj->object_id) && preg_match("/^Move_Up_Object_".$obj->object_id."_/",$name) && $once){
+ $this->current_handler->tree_->move_up_down($key,"up");
+ $once = FALSE;
+ }
+ if(isset($obj->object_id) && preg_match("/^Move_Down_Object_".$obj->object_id."_/",$name) && $once){
+ $this->current_handler->tree_->move_up_down($key,"down");
+ $once = FALSE;
+ }
+ }
+ }
+
+ /* Skip Mode changes and Parse tests
+ * if we are currently in a subdialog
+ */
+ if(!$this->add_new_element) {
+
+ $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;
+ if($p -> parse($sc)){
+ $this->current_handler = $p;
+ $this->Script_Error = "";
+ } else {
+ $this->Script_Error = $p->status_text;
+ $skip_mode_change = TRUE;
+ }
+ }
+ }
+ if(in_array($Mode,array("Structured"))){
+ $this->current_handler->save_object();
+ $sc = $this->current_handler->get_sieve_script();
$this->scripts[$this->current_script]['SCRIPT'] = $sc;
$p = new My_Parser;
if($p -> parse($sc)){
$this->current_handler = $p;
+ $this->Script_Error = "";
} else {
- print_red($p->status_text);
+ $this->Script_Error = $p->status_text;
$skip_mode_change = TRUE;
}
}
- }
- if(in_array($Mode,array("Structured"))){
- $this->current_handler->save_object();
- $sc = $this->current_handler->get_sieve_script();
- $this->scripts[$this->current_script]['SCRIPT'] = $sc;
- $p = new My_Parser;
- if($p -> parse($sc)){
- $this->current_handler = $p;
- } else {
- print_red($p->status_text);
- $skip_mode_change = TRUE;
- }
- }
- if(!$skip_mode_change){
- if($this->scripts[$this->current_script]['MODE'] != "Source-Only"){
- if(isset($_POST['View_Source'])){
- $this->scripts[$this->current_script]['MODE'] = "Source";
- }
- if(isset($_POST['View_Structured'])){
- $this->scripts[$this->current_script]['MODE'] = "Structured";
+ if(!$skip_mode_change){
+ if($this->scripts[$this->current_script]['MODE'] != "Source-Only"){
+ if(isset($_POST['View_Source'])){
+ $this->scripts[$this->current_script]['MODE'] = "Source";
+ }
+ if(isset($_POST['View_Structured'])){
+ $this->scripts[$this->current_script]['MODE'] = "Structured";
+ }
}
}
}
diff --git a/include/sieve/templates/edit_frame_base.tpl b/include/sieve/templates/edit_frame_base.tpl
index ad18e89c0f3cd33f6019eac44d29ad8f32aebc20..1f80feb967952f05a0e9886f2ac046aee40c43e6 100644 (file)
-<table style='width:100%;' cellspacing=0 cellpadding=0>
+<table style='width:100%;' cellspacing=0 cellpadding=0>
<tr>
<td style='background-color: #CCCCCC; padding:5px;'>
<tr>
<td style='background-color: #FFFFFF; border: solid 2px #CCCCCC; '>
+ {if $Script_Error != ""}
+ <table style='width:100%;' cellspacing=0 cellpadding=0>
+ <tr>
+ <td style='background-color: orange;padding:5px;'>
+ <b>{$Script_Error}</b>
+ </td>
+ </tr>
+ </table>
+ {/if}
+
+
{if $Mode == "Structured"}
{$Contents}
{else}