SF.net SVN: postfixadmin:[1163] trunk
Brought to you by:
christian_boltz,
gingerdog
From: <chr...@us...> - 2011-08-05 20:01:44
|
Revision: 1163 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=1163&view=rev Author: christian_boltz Date: 2011-08-05 20:01:35 +0000 (Fri, 05 Aug 2011) Log Message: ----------- Merged edit-vacation.tpl and users_vacation.tpl. Prepare merging of edit-vacation.php and users/vacation.php users/vacation.php, edit-vacation.php: - first step of merging - renamed some variables to fit vacation.tpl - some code sorting and cleanup - replaced JS redirect on cancel with handling in PHP users_vacation.tpl, edit-vacation.tpl: - deleted (merged to vacation.tpl) vacation.tpl: - new file, result of merging edit-vacation.tpl and users_vacation.tpl - display mail address to users also (to be discussed) Thanks to J.Kruis (jan-kruis@SF) for the patch, https://sourceforge.net/tracker/?func=detail&aid=3383236&group_id=191583&atid=937966 Modified Paths: -------------- trunk/edit-vacation.php trunk/users/vacation.php Added Paths: ----------- trunk/templates/vacation.tpl Removed Paths: ------------- trunk/templates/edit-vacation.tpl trunk/templates/users_vacation.tpl Modified: trunk/edit-vacation.php =================================================================== --- trunk/edit-vacation.php 2011-08-04 11:34:55 UTC (rev 1162) +++ trunk/edit-vacation.php 2011-08-05 20:01:35 UTC (rev 1163) @@ -25,6 +25,7 @@ * * Form POST \ GET Variables: * + * fRole * fUsername * fDomain * fCanceltarget @@ -41,6 +42,13 @@ exit(0); } +// TODO +// Get the $Role of who wants to modify vacation setiing [admin of user] +// on $Role get correct Username and domain of emailname +// for wtich we are going to modify thet vacation setting. +// This has to by don up front before display new windows. + + $SESSID_USERNAME = authentication_get_username(); $tmp = preg_split ('/@/', $SESSID_USERNAME); $USERID_DOMAIN = $tmp[1]; @@ -59,41 +67,48 @@ $vh = new VacationHandler($fUsername); -$fCanceltarget = "list-virtual.php?domain=$fDomain"; if ($_SERVER['REQUEST_METHOD'] == "GET") { + $tSubject = ''; + $tBody = ''; + $tActiveFrom = ''; + $tActiveUntil = ''; - $result = db_query("SELECT * FROM $table_vacation WHERE email='$fUsername'"); - if ($result['rows'] == 1) - { - $row = db_array($result['result']); - $tSubject = $row['subject']; - $tBody = $row['body']; - $tActiveFrom = $row['activefrom']; - $tActiveUntil = $row['activeuntil']; - } + $details = $vh->get_details(); + if($details != false) { + $tSubject = $details['subject']; + $tBody = $details['body']; + $tActiveFrom = $details['activeFrom']; + $tActiveUntil = $details['activeUntil']; + } $tUseremail = $fUsername; $tDomain = $fDomain; + + //set a default, reset fields for coming back selection if ($tSubject == '') { $tSubject = html_entity_decode($PALANG['pUsersVacation_subject_text'], ENT_QUOTES, 'UTF-8'); } if ($tBody == '') { $tBody = html_entity_decode($PALANG['pUsersVacation_body_text'], ENT_QUOTES, 'UTF-8'); } - } if ($_SERVER['REQUEST_METHOD'] == "POST") { + if(isset($_POST['fCancel'])) { + header("Location: list-virtual.php?domain=$fDomain"); + exit(0); + } + $tActiveFrom = date ("Y-m-d 00:00:00", strtotime (safepost('fActiveFrom'))); + $tActiveUntil = date ("Y-m-d 23:59:59", strtotime (safepost('fActiveUntil'))); + $tSubject = safepost('fSubject'); - $fSubject = escape_string ($tSubject); + $fSubject = $tSubject; $tBody = safepost('fBody'); -// $tActiveFrom = safepost('activefrom').' 00:00:01'; -// $tActiveUntil = safepost('activeuntil').' 23:59:59'; - $tActiveFrom = date ("Y-m-d 00:00:00", strtotime (safepost('activefrom'))); - $tActiveUntil = date ("Y-m-d 23:59:59", strtotime (safepost('activeuntil'))); - $fBody = escape_string ($tBody); + $fBody = $tBody; + $fChange = escape_string (safepost('fChange')); $fBack = escape_string (safepost('fBack')); + if(authentication_has_role('admin') && isset($_GET['domain'])) { $fDomain = escape_string ($_GET['domain']); } @@ -108,9 +123,19 @@ } $tUseremail = $fUsername; + + //set a default, reset fields for coming back selection if ($tSubject == '') { $tSubject = html_entity_decode($PALANG['pUsersVacation_subject_text'], ENT_QUOTES, 'UTF-8'); } if ($tBody == '') { $tBody = html_entity_decode($PALANG['pUsersVacation_body_text'], ENT_QUOTES, 'UTF-8'); } + //Set the vacation data for $fUsername + if (!empty ($fChange)) + { + if(!$vh->set_away($fSubject, $fBody, $tActiveFrom, $tActiveUntil)) { + $error = 1; + } + } + //if change, remove old one, then perhaps set new one if (!empty ($fBack)) { @@ -119,40 +144,38 @@ } } - - //Set the vacation data for $fUsername - if (!empty ($fChange)) - { - if(!$vh->set_away($fSubject, $fBody, $tActiveFrom, $tActiveUntil)) { - $error = 1; - } - - } } - +// If NO error then diplay flash message and go back to right url where we came from if($error == 0) { if(!empty ($fBack)) { - flash_info($PALANG['pVacation_result_removed']); + $Flash_Message = $PALANG['pVacation_result_removed'] ; //TODO adding useremail to flash info depending on $Role + flash_info($Flash_Message); + header ("Location: list-virtual.php?domain=$fDomain"); + exit; } if(!empty($fChange)) { - flash_info($PALANG['pVacation_result_added']); + $Flash_Message =( $PALANG['pVacation_result_added']); //TODO adding useremail to flash info depending on $Role + flash_info($Flash_Message); + header ("Location: list-virtual.php?domain=$fDomain"); + exit; } } else { - flash_error($PALANG['pVacation_result_error']); + $Flash_Message = $PALANG['pVacation_result_error'] ; //TODO adding useremail to flash info depending on $Role + flash_error($Flash_Message); } if (empty ($tActiveFrom)) $tActiveFrom = date ("Y-m-d"); if (empty ($tActiveUntil)) $tActiveUntil = date ("Y-m-d"); + $smarty->assign ('tUseremail', $tUseremail); $smarty->assign ('tSubject', $tSubject); -$smarty->assign ('tBody', $tBody ,false); +$smarty->assign ('tBody', $tBody); $smarty->assign ('tActiveFrom', date ("d.m.Y", strtotime ($tActiveFrom))); $smarty->assign ('tActiveUntil', date ("d.m.Y", strtotime ($tActiveUntil))); -$smarty->assign ('fCanceltarget', $fCanceltarget); -$smarty->assign ('smarty_template', 'edit-vacation'); +$smarty->assign ('smarty_template', 'vacation'); $smarty->display ('index.tpl'); /* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */ Deleted: trunk/templates/edit-vacation.tpl =================================================================== --- trunk/templates/edit-vacation.tpl 2011-08-04 11:34:55 UTC (rev 1162) +++ trunk/templates/edit-vacation.tpl 2011-08-05 20:01:35 UTC (rev 1163) @@ -1,68 +0,0 @@ -{literal} - <script language="JavaScript" type="text/javascript"> - function newLocation() { - window.location="{/literal}{$fCanceltarget}{literal}" - } - </script> - <script language="JavaScript" src="calendar.js" type="text/javascript"></script> -{/literal} -<div id="edit_form"> -<form name="edit-vacation" method="post" action=''> -<table> - <tr> - <th colspan="3">{$PALANG.pUsersVacation_welcome}</th> - </tr> - <tr> - <td class="label"><label>{$PALANG.pUsersLogin_username}:</label></td> - <td><em>{$tUseremail}</em></td> - <td> </td> - </tr> - <tr> - <td class="label"><label>{$PALANG.pUsersVacation_activefrom}:</label></td> - <td><input class="flat readonly" name="activefrom" value="{$tActiveFrom}" readonly="readonly" /> -{literal} -<script language="JavaScript" type="text/javascript"> - new tcal ({ - 'formname': 'edit-vacation', - 'controlname': 'activefrom' - }); -</script> -{/literal} - </td> - <td> </td> - </tr> - <tr> - <td class="label"><label>{$PALANG.pUsersVacation_activeuntil}:</label></td> - <td><input class="flat readonly" name="activeuntil" value="{$tActiveUntil}" readonly="readonly" /> -{literal} -<script language="JavaScript" type="text/javascript"> - new tcal ({ - 'formname': 'edit-vacation', - 'controlname': 'activeuntil' - }); -</script> -{/literal} - </td> - <td> </td> - </tr> - <tr> - <td class="label"><label>{$PALANG.pUsersVacation_subject}:</label></td> - <td><textarea class="flat" rows="3" cols="60" name="fSubject" >{$tSubject}</textarea></td> - <td> </td> - </tr> - <tr> - <td class="label"><label>{$PALANG.pUsersVacation_body}:</label></td> - <td><textarea class="flat" rows="10" cols="60" name="fBody" >{$tBody}</textarea></td> - <td> </td> - </tr> - <tr> - <td> </td> - <td colspan="2"> - <input class="button" type="submit" name="fChange" value="{$PALANG.pEdit_vacation_set}" /> - <input class="button" type="submit" name="fBack" value="{$PALANG.pEdit_vacation_remove}" /> - <input class="button" type="button" name="fCancel" value="{$PALANG.exit}" onclick="newLocation()" /> - </td> - </tr> -</table> -</form> -</div> Deleted: trunk/templates/users_vacation.tpl =================================================================== --- trunk/templates/users_vacation.tpl 2011-08-04 11:34:55 UTC (rev 1162) +++ trunk/templates/users_vacation.tpl 2011-08-05 20:01:35 UTC (rev 1163) @@ -1,63 +0,0 @@ -{literal} - <script language="JavaScript" type="text/javascript"> - function newLocation() { - window.location="{/literal}{$fCanceltarget}{literal}" - } - </script> - <script language="JavaScript" src="calendar.js" type="text/javascript"></script> -{/literal} -<div id="edit_form"> -<form name="vacation" method="post" action=''> -<table> - <tr> - <th colspan="3">{$PALANG.pUsersVacation_welcome}</th> - </tr> - <tr> - <td class="label"><label>{$PALANG.pUsersVacation_activefrom}:</label></td> - <td><input class="flat readonly" name="fActiveFrom" value="{$tActiveFrom}" readonly="readonly" /> -{literal} -<script language="JavaScript" type="text/javascript"> - new tcal ({ - 'formname': 'vacation', - 'controlname': 'fActiveFrom' - }); -</script> -{/literal} - </td> - <td> </td> - </tr> - <tr> - <td class="label"><label>{$PALANG.pUsersVacation_activeuntil}:</label></td> - <td><input class="flat readonly" name="fActiveUntil" value="{$tActiveUntil}" readonly="readonly" /> -{literal} -<script language="JavaScript" type="text/javascript"> - new tcal ({ - 'formname': 'vacation', - 'controlname': 'fActiveUntil' - }); -</script> -{/literal} - </td> - <td> </td> - </tr> - <tr> - <td class="label"><label>{$PALANG.pUsersVacation_subject}:</label></td> - <td><textarea class="flat" rows="3" cols="60" name="fSubject" >{$tSubject}</textarea></td> - <td> </td> - </tr> - <tr> - <td class="label"><label>{$PALANG.pUsersVacation_body}:</label></td> - <td><textarea class="flat" rows="10" cols="60" name="fBody" >{$tBody}</textarea></td> - <td> </td> - </tr> - <tr> - <td> </td> - <td colspan="2"> - <input class="button" type="submit" name="fAway" value="{$PALANG.pUsersVacation_button_away}" /> - <input class="button" type="submit" name="fBack" value="{$PALANG.pUsersVacation_button_back}" /> - <input class="button" type="submit" name="fCancel" value="{$PALANG.exit}" /> - </td> - </tr> -</table> -</form> -</div> Copied: trunk/templates/vacation.tpl (from rev 1154, trunk/templates/edit-vacation.tpl) =================================================================== --- trunk/templates/vacation.tpl (rev 0) +++ trunk/templates/vacation.tpl 2011-08-05 20:01:35 UTC (rev 1163) @@ -0,0 +1,63 @@ +{literal} + <script language="JavaScript" src="calendar.js" type="text/javascript"></script> +{/literal} +<div id="edit_form"> +<form name="edit-vacation" method="post" action=''> +<table> + <tr> + <th colspan="3">{$PALANG.pUsersVacation_welcome}</th> + </tr> + <tr> + <td class="label"><label>{$PALANG.pUsersLogin_username}:</label></td> + <td><em>{$tUseremail}</em></td> + <td> </td> + </tr> + <tr> + <td class="label"><label>{$PALANG.pUsersVacation_activefrom}:</label></td> + <td><input class="flat readonly" name="fActiveFrom" value="{$tActiveFrom}" readonly="readonly" /> +{literal} +<script language="JavaScript" type="text/javascript"> + new tcal ({ + 'formname': 'edit-vacation', + 'controlname': 'fActiveFrom' + }); +</script> +{/literal} + </td> + <td> </td> + </tr> + <tr> + <td class="label"><label>{$PALANG.pUsersVacation_activeuntil}:</label></td> + <td><input class="flat readonly" name="fActiveUntil" value="{$tActiveUntil}" readonly="readonly" /> +{literal} +<script language="JavaScript" type="text/javascript"> + new tcal ({ + 'formname': 'edit-vacation', + 'controlname': 'fActiveUntil' + }); +</script> +{/literal} + </td> + <td> </td> + </tr> + <tr> + <td class="label"><label>{$PALANG.pUsersVacation_subject}:</label></td> + <td><textarea class="flat" rows="3" cols="60" name="fSubject" >{$tSubject}</textarea></td> + <td> </td> + </tr> + <tr> + <td class="label"><label>{$PALANG.pUsersVacation_body}:</label></td> + <td><textarea class="flat" rows="10" cols="60" name="fBody" >{$tBody}</textarea></td> + <td> </td> + </tr> + <tr> + <td> </td> + <td colspan="2"> + <input class="button" type="submit" name="fChange" value="{$PALANG.pEdit_vacation_set}" /> + <input class="button" type="submit" name="fBack" value="{$PALANG.pEdit_vacation_remove}" /> + <input class="button" type="submit" name="fCancel" value="{$PALANG.exit}" /> + </td> + </tr> +</table> +</form> +</div> Modified: trunk/users/vacation.php =================================================================== --- trunk/users/vacation.php 2011-08-04 11:34:55 UTC (rev 1162) +++ trunk/users/vacation.php 2011-08-05 20:01:35 UTC (rev 1163) @@ -26,7 +26,7 @@ * * fSubject * fBody - * fAway + * fChange * fBack */ @@ -34,6 +34,7 @@ authentication_require_role('user'); $USERID_USERNAME = authentication_get_username(); +$fUsername = authentication_get_username(); // is vacation support enabled in $CONF ? if($CONF['vacation'] == 'NO') { @@ -43,26 +44,31 @@ date_default_timezone_set(@date_default_timezone_get()); # Suppress date.timezone warnings -$vh = new VacationHandler(authentication_get_username()); +$vh = new VacationHandler($fUsername); +//$vh = new VacationHandler(authentication_get_username()); if ($_SERVER['REQUEST_METHOD'] == "GET") { $tSubject = ''; $tBody = ''; - $tActiveFrom = ''; - $tActiveUntil = ''; - - $details = $vh->get_details(); - if($details != false) { + $tActiveFrom = ''; + $tActiveUntil = ''; + + $details = $vh->get_details(); + if($details != false) { $tSubject = $details['subject']; - $tBody = $details['body']; - $fActiveFrom = $details['activeFrom']; - $fActiveUntil = $details['activeUntil']; + $tBody = $details['body']; + $fActiveFrom = $details['activeFrom']; + $fActiveUntil = $details['activeUntil']; } + if($vh->check_vacation()) { flash_info($PALANG['pUsersVacation_welcome_text']); } + $tUseremail = $fUsername; + + //set a default, reset fields for coming back selection if ($tSubject == '') { $tSubject = html_entity_decode($PALANG['pUsersVacation_subject_text'], ENT_QUOTES, 'UTF-8'); } if ($tBody == '') { $tBody = html_entity_decode($PALANG['pUsersVacation_body_text'], ENT_QUOTES, 'UTF-8'); } } @@ -74,49 +80,93 @@ exit(0); } - if (isset ($_POST['fSubject'])) $fSubject = $_POST['fSubject']; - if (isset ($_POST['fBody'])) $fBody = $_POST['fBody']; - if (isset ($_POST['fAway'])) $fAway = escape_string ($_POST['fAway']); - if (isset ($_POST['fBack'])) $fBack = escape_string ($_POST['fBack']); - if (isset ($_POST['fActiveFrom'])) $tActiveFrom = date ("Y-m-d 00:00:00", strtotime ($_POST['fActiveFrom'])); - if (isset ($_POST['fActiveUntil'])) $tActiveUntil = date ("Y-m-d 23:59:59", strtotime ($_POST['fActiveUntil'])); + $tActiveFrom = date ("Y-m-d 00:00:00", strtotime (safepost('fActiveFrom'))); + $tActiveUntil = date ("Y-m-d 23:59:59", strtotime (safepost('fActiveUntil'))); + + $tSubject = safepost('fSubject'); + $fSubject = $tSubject; + $tBody = safepost('fBody'); + $fBody = $tBody; + + $fChange = escape_string (safepost('fChange')); + $fBack = escape_string (safepost('fBack')); + + $tUseremail = $fUsername; + //set a default, reset fields for coming back selection if ($tSubject == '') { $tSubject = html_entity_decode($PALANG['pUsersVacation_subject_text'], ENT_QUOTES, 'UTF-8'); } if ($tBody == '') { $tBody = html_entity_decode($PALANG['pUsersVacation_body_text'], ENT_QUOTES, 'UTF-8'); } - // if they've set themselves away OR back, delete any record of vacation emails. + // if they've set themselves change OR back, delete any record of vacation emails. + // the user is going away - set the goto alias and vacation table as necessary. - // the user is going away - set the goto alias and vacation table as necessary. - if (!empty ($fAway)) - { - if(!$vh->set_away($fSubject, $fBody, $tActiveFrom, $tActiveUntil)) { +// if (!empty ($fChange)) +// { +// if(!$vh->set_away($fSubject, $fBody, $tActiveFrom, $tActiveUntil)) { +// $error = 1; +// flash_error($PALANG['pUsersVacation_result_error']); +// } +// flash_info($PALANG['pVacation_result_added']); +// header ("Location: main.php"); +// exit; +// } +// +// if (!empty ($fBack)) { +// $vh->remove(); +// flash_info($PALANG['pUsersVacation_result_success']); +// header ("Location: main.php"); +// exit; +// } + + //Set the vacation data for $fUsername + if (!empty ($fChange)) + { + if(!$vh->set_away($fSubject, $fBody, $tActiveFrom, $tActiveUntil)) { $error = 1; - flash_error($PALANG['pUsersVacation_result_error']); } - flash_info($PALANG['pVacation_result_added']); - header ("Location: main.php"); - exit; - } + } - if (!empty ($fBack)) { - $vh->remove(); - flash_info($PALANG['pUsersVacation_result_success']); - header ("Location: main.php"); - exit; - } + //if change, remove old one, then perhaps set new one + if (!empty ($fBack)) + { + if(!$vh->remove()) { + $error = 1; + } + } + } +// If NO error then diplay flash message and go back to right url where we came from +if($error == 0) { + if(!empty ($fBack)) { + $Flash_Message = $PALANG['pVacation_result_removed'] ; //TODO adding useremail to flash info depending on $ + flash_info($Flash_Message); + header ("Location: main.php"); + exit; + } + if(!empty($fChange)) { + $Flash_Message =( $PALANG['pVacation_result_added']); //TODO adding useremail to flash info depending on $$ + flash_info($Flash_Message); + header ("Location: main.php"); + exit; + } +} +else { + $Flash_Message = $PALANG['pVacation_result_error'] ; //TODO adding useremail to flash info depending on $Role + flash_error($Flash_Message); +} if (empty ($fActiveFrom)) $fActiveFrom = date ("Y-m-d"); if (empty ($fActiveUntil)) $fActiveUntil = date ("Y-m-d"); - -$smarty->assign ('tSubject', htmlentities ($tSubject, ENT_QUOTES, 'UTF-8'), false); -$smarty->assign ('tBody', htmlentities ($tBody, ENT_QUOTES, 'UTF-8'), false); + +$smarty->assign ('tUseremail', $tUseremail); +$smarty->assign ('tSubject', $tSubject); +$smarty->assign ('tBody', $tBody); $smarty->assign ('tActiveFrom', date ("d.m.Y", strtotime ($fActiveFrom))); $smarty->assign ('tActiveUntil', date ("d.m.Y", strtotime ($fActiveUntil))); -$smarty->assign ('smarty_template', 'users_vacation'); +$smarty->assign ('smarty_template', 'vacation'); $smarty->display ('index.tpl'); /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */ ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |