2019-10-26 12:35:06 +00:00
< ? php
/**
* Project :
* Contenido Content Management System
*
* Description :
* Frontend user editor
*
* Requirements :
* @ con_php_req 5.0
*
*
* @ package Contenido Backend includes
* @ version 1.0 . 0
* @ author Bj<EFBFBD> rn Behrens ( HerrB )
* @ copyright four for business AG < www . 4 fb . de >
* @ license http :// www . contenido . org / license / LIZENZ . txt
* @ link http :// www . 4 fb . de
* @ link http :// www . contenido . org
* @ since file available since contenido release <= 4.6
*
* { @ internal
* created 2007 - 01 - 01 , Bj<EFBFBD> rn Behrens ( HerrB )
* modified 2008 - 06 - 27 , Dominik Ziegler , add security fix
*
* $Id : include . newsletter_edit_message . php 128 2019 - 07 - 03 11 : 58 : 28 Z oldperl $ :
* }}
*
*/
if ( ! defined ( 'CON_FRAMEWORK' )) {
die ( 'Illegal call' );
}
cInclude ( " includes " , " functions.con.php " ); // For conDeleteArt and conCopyArt
// Initialization
$oPage = new cPage ;
$oClientLang = new cApiClientLanguage ( false , $client , $lang );
// Include plugins
if ( is_array ( $cfg [ 'plugins' ][ 'newsletters' ])) {
foreach ( $cfg [ 'plugins' ][ 'newsletters' ] as $plugin ) {
plugin_include ( " newsletters " , $plugin . " / " . $plugin . " .php " );
}
}
// Exec actions
$oNewsletter = new Newsletter ;
$oNewsletter -> loadByPrimaryKey ( $idnewsletter );
if ( $oNewsletter -> virgin == false && $oNewsletter -> get ( " idclient " ) == $client && $oNewsletter -> get ( " idlang " ) == $lang ) {
// Check and set values
if ( ! is_numeric ( $_REQUEST [ " selTemplate " ])) {
$_REQUEST [ " selTemplate " ] = 0 ;
}
// Saving message changes; note, that if a user doesn't have the right to save the
// text message he may still have the right to change the html article. To prevent
// changing the html article, give the user only read access right for the newsletter
// article category - the article will be shown also, if he doesn't have any rights at all...
if ( $action == " news_save " && $perm -> have_perm_area_action ( " news " , $action )) { // Don't use $area!
// Changing e.g. \' back to ' (magic_quotes)
$sMessage = Contenido_Security :: unescapeDB ( $_REQUEST [ " txtMessage " ]);
$oNewsletter -> set ( " message " , $sMessage );
if ( $oNewsletter -> get ( " template_idart " ) != $_REQUEST [ " selTemplate " ]) {
if ( $oNewsletter -> get ( " idart " ) > 0 ) {
// Template has been changed: Delete old article
// (this discards the current html content as it deletes the existing newsletter article)
conDeleteArt ( $oNewsletter -> get ( " idart " ));
$iIDArt = 0 ;
}
if ( $_REQUEST [ " selTemplate " ] > 0 ) {
// Template has been changed, but specified: Store template article as new newsletter article
2021-04-26 18:28:43 +00:00
$iIDArt = conCopyArticle ( $_REQUEST [ " selTemplate " ], $oClientLang -> getProperty ( " newsletter " , " html_newsletter_idcat " ), sprintf ( i18n ( " Newsletter: %s " , " cl-newsletter " ), $oNewsletter -> get ( " name " )));
2019-10-26 12:35:06 +00:00
conMakeOnline ( $iIDArt , $lang ); // Article has to be online for sending...
}
$oNewsletter -> set ( " idart " , $iIDArt );
$oNewsletter -> set ( " template_idart " , $_REQUEST [ " selTemplate " ]);
}
$oNewsletter -> store ();
} else if ( $oNewsletter -> get ( " idart " ) > 0 ) {
// Check, if html message article and template article are still available
$oArticles = new cApiArticleLanguageCollection ;
$oArticles -> setWhere ( " idlang " , $lang );
$oArticles -> setWhere ( " idart " , $oNewsletter -> get ( " idart " ));
$oArticles -> query ();
if ( $oArticles -> count () == 0 ) {
// Ups, article lost, reset idart and template_idart for newsletter
2021-04-26 18:28:43 +00:00
$notis = $notification -> returnNotification ( " error " , sprintf ( i18n ( " The html newsletter article has been deleted (idart: %s), the html message is lost " , " cl-newsletter " ), $oNewsletter -> get ( " idart " ))) . " <br> " ;
2019-10-26 12:35:06 +00:00
$oNewsletter -> set ( " idart " , 0 );
$oNewsletter -> set ( " template_idart " , 0 );
$oNewsletter -> store ();
} else {
$oArticles -> resetQuery ();
$oArticles -> setWhere ( " idlang " , $lang );
$oArticles -> setWhere ( " idart " , $oNewsletter -> get ( " template_idart " ));
$oArticles -> query ();
if ( $oArticles -> count () == 0 ) {
// Ups, template has been deleted: Restore from current newsletter message article
2021-04-26 18:28:43 +00:00
$notis = $notification -> returnNotification ( " warning " , i18n ( " The html newsletter template article has been deleted, it has been restored using the html message article of this newsletter " , " cl-newsletter " )) . " <br> " ;
2019-10-26 12:35:06 +00:00
2021-04-26 18:28:43 +00:00
$iIDArt = conCopyArticle ( $oNewsletter -> get ( " idart " ), $oClientLang -> getProperty ( " newsletter " , " html_template_idcat " ), sprintf ( i18n ( " %s (Template restored) " , " cl-newsletter " ), $oNewsletter -> get ( " name " )));
2019-10-26 12:35:06 +00:00
$oNewsletter -> set ( " template_idart " , $iIDArt );
$oNewsletter -> store ();
}
}
}
$oForm = new UI_Table_Form ( " frmNewsletterMsg " );
$oForm -> setVar ( " frame " , $frame );
$oForm -> setVar ( " area " , $area );
$oForm -> setVar ( " action " , " news_save " );
$oForm -> setVar ( " idnewsletter " , $idnewsletter );
$oForm -> setWidth ( " 100% " );
2021-04-26 18:28:43 +00:00
$oForm -> addHeader ( sprintf ( i18n ( " Edit newsletter message (%s) " , " cl-newsletter " ), $oNewsletter -> get ( " name " )));
2019-10-26 12:35:06 +00:00
$oForm -> add ( i18n ( " Subject " ), $oNewsletter -> get ( " subject " ));
2021-04-26 18:28:43 +00:00
$sTagInfoText = '<a href="javascript:fncShowHide(\'idTagInfoText\');"><strong>' . i18n ( " Tag information " , " cl-newsletter " ) . '</strong></a>' .
'<div id="idTagInfoText" style="display: none"><br /><b>' . i18n ( " Special message tags (will be replaced when sending) " , " cl-newsletter " ) . ':</b><br>' .
'MAIL_NAME: ' . i18n ( " Name of the recipient " , " cl-newsletter " ) . '<br />' .
'MAIL_DATE: ' . i18n ( " Date, when the mail has been sent " , " cl-newsletter " ) . '<br />' .
'MAIL_TIME: ' . i18n ( " Time, when the mail has been sent " , " cl-newsletter " ) . '<br />' .
'MAIL_NUMBER: ' . i18n ( " Number of recipients " , " cl-newsletter " ) . '<br />' .
#'MAIL_CHANGE: '.i18n("Link to change the e-mail adress", "cl-newsletter").'<br />'.
'MAIL_UNSUBSCRIBE: ' . i18n ( " Link to unsubscribe " , " cl-newsletter " ) . '<br />' .
'MAIL_STOP: ' . i18n ( " Link to pause the subscription " , " cl-newsletter " ) . '<br />' .
'MAIL_GOON: ' . i18n ( " Link to resume the subscription " , " cl-newsletter " );
$sTagInfoHTML = '<a href="javascript:fncShowHide(\'idTagInfoHTML\');"><strong>' . i18n ( " Tag information " , " cl-newsletter " ) . '</strong></a>' .
'<div id="idTagInfoHTML" style="display: none"><br /><b>' . i18n ( " Special message tags (will be replaced when sending, { ..} = optional) " , " cl-newsletter " ) . " :</b><br /> " .
'[mail name="name" type="text"]{text}MAIL_NAME{text}[/mail]: ' . i18n ( " Name of the recipient " , " cl-newsletter " ) . " <br /> " .
'[mail name="date" type="text"]{text}MAIL_DATE{text}[/mail]: ' . i18n ( " Date, when the mail has been sent " , " cl-newsletter " ) . " <br /> " .
'[mail name="time" type="text"]{text}MAIL_TIME{text}[/mail]: ' . i18n ( " Time, when the mail has been sent " , " cl-newsletter " ) . " <br /> " .
'[mail name="number" type="text"]{text}MAIL_NUMBER{text}[/mail]: ' . i18n ( " Number of recipients " , " cl-newsletter " ) . " <br /> " .
#'[mail name="change" type="link" {text="'.i18n("Link text", "cl-newsletter").'"}]{text}MAIL_CHANGE{text}[/mail]: '.i18n("Link to change the e-mail adress", "cl-newsletter")."<br />".
'[mail name="unsubscribe" type="link" {text="' . i18n ( " Link text " , " cl-newsletter " ) . '" }]{text}MAIL_UNSUBSCRIBE{text}[/mail]: ' . i18n ( " Link to unsubscribe " , " cl-newsletter " ) . " <br /> " .
'[mail name="stop" type="link" {text="' . i18n ( " Link text " , " cl-newsletter " ) . '" }]{text}MAIL_STOP{text}[/mail]: ' . i18n ( " Link to pause the subscription " , " cl-newsletter " ) . " <br /> " .
'[mail name="goon" type="link" {text="' . i18n ( " Link text " , " cl-newsletter " ) . '" }]{text}MAIL_GOON{text}[/mail]: ' . i18n ( " Link to resume the subscription " , " cl-newsletter " );
2019-10-26 12:35:06 +00:00
// Mention plugin interface
if ( getSystemProperty ( " newsletter " , " newsletter-recipients-plugin " ) == " true " ) {
2021-04-26 18:28:43 +00:00
$sTagInfoText .= " <br /><br /><strong> " . i18n ( " Additional message tags from recipients plugins: " , " cl-newsletter " ) . " </strong><br /> " ;
$sTagInfoHTML .= " <br /><br /><strong> " . i18n ( " Additional message tags from recipients plugins: " , " cl-newsletter " ) . " </strong><br /> " ;
2019-10-26 12:35:06 +00:00
if ( is_array ( $cfg [ 'plugins' ][ 'recipients' ])) {
foreach ( $cfg [ 'plugins' ][ 'recipients' ] as $plugin ) {
plugin_include ( " recipients " , $plugin . " / " . $plugin . " .php " );
if ( function_exists ( " recipients_ " . $plugin . " _wantedVariables " )) {
$aPluginVars = call_user_func ( " recipients_ " . $plugin . " _wantedVariables " );
foreach ( $aPluginVars as $sPluginVar ) {
$sTagInfoText .= 'MAIL_' . strtoupper ( $sPluginVar ) . '<br />' ;
$sTagInfoHTML .= '[mail name="' . strtolower ( $sPluginVar ) . '" type="text"][/mail]<br />' ;
}
}
}
}
} else {
setSystemProperty ( " newsletter " , " newsletter-recipients-plugin " , " false " ); // -> Property available in system settings
}
$sTagInfoText .= " </div> " ;
$sTagInfoHTML .= " </div> " ;
$iTplIDArt = 0 ; // Used later for on change event
if ( $oNewsletter -> get ( " type " ) == " html " ) {
$iTplIDArt = $oNewsletter -> get ( " template_idart " );
$oSelTemplate = new cHTMLSelectElement ( " selTemplate " );
$oSelTemplate -> setEvent ( " change " , " askSubmitOnTplChange(this); " );
$aOptions = array ( " idcat " => $oClientLang -> getProperty ( " newsletter " , " html_template_idcat " ),
" start " => true ,
" offline " => true ,
" order " => " title " );
$oTemplateArticles = new ArticleCollection ( $aOptions );
$aItems = array ();
2021-04-26 18:28:43 +00:00
$aItems [] = array ( 0 , i18n ( " -- none -- " , " cl-newsletter " ));
2019-10-26 12:35:06 +00:00
while ( $oArticle = $oTemplateArticles -> nextArticle ()) {
$aItems [] = array ( $oArticle -> get ( " idart " ), $oArticle -> get ( " title " ));
}
$oSelTemplate -> autoFill ( $aItems );
$oSelTemplate -> setDefault ( $iTplIDArt );
unset ( $aItems );
unset ( $oArticles );
unset ( $oTemplateArticles );
2021-04-26 18:28:43 +00:00
$oForm -> add ( i18n ( " HTML Template " , " cl-newsletter " ), $oSelTemplate -> render () . " " . i18n ( " Note, that changing the template discards the current html message content " , " cl-newsletter " ));
2019-10-26 12:35:06 +00:00
if ( $iTplIDArt != 0 ) {
$sFrameSrc = $cfgClient [ $client ][ " path " ][ " htmlpath " ] . " front_content.php?changeview=edit&action=con_editart&idart= " . $oNewsletter -> get ( " idart " ) . " &idcat= " . $oClientLang -> getProperty ( " newsletter " , " html_newsletter_idcat " ) . " &lang= " . $lang . " &contenido= " . $sess -> id ;
2021-04-26 18:28:43 +00:00
$oForm -> add ( i18n ( " HTML Message " , " cl-newsletter " ), '<iframe width="100%" height="600" src="' . $sFrameSrc . '"></iframe><br />' . $sTagInfoHTML );
2019-10-26 12:35:06 +00:00
} else {
// Add a real note, that a template has to be specified
2021-04-26 18:28:43 +00:00
$notis .= $notification -> returnNotification ( " warning " , i18n ( " Newsletter type has been set to HTML/text, please remember to select an html template " , " cl-newsletter " )) . " <br /> " ;
2019-10-26 12:35:06 +00:00
2021-04-26 18:28:43 +00:00
$oForm -> add ( i18n ( " HTML Message " , " cl-newsletter " ), i18n ( " Please choose a template first " , " cl-newsletter " ));
2019-10-26 12:35:06 +00:00
}
}
$oTxtMessage = new cHTMLTextarea ( " txtMessage " , $oNewsletter -> get ( " message " ), 80 , 20 );
2021-04-26 18:28:43 +00:00
$oForm -> add ( i18n ( " Text Message " , " cl-newsletter " ), $oTxtMessage -> render () . " <br /> " . $sTagInfoText );
2019-10-26 12:35:06 +00:00
$sExecScript = '
< script type = " text/javascript " >
// Enabled/Disable group box
function fncShowHide ( strItemID ) {
objItem = document . getElementById ( strItemID );
if ( objItem . style . display == " none " ) {
objItem . style . display = " inline " ;
} else {
objItem . style . display = " none " ;
}
}
// Create messageBox instance
box = new messageBox ( " " , " " , " " , 0 , 0 );
// If html newsletter template selection has changed, ask user
// if he/she may like to save this change (e.g. to get an html
// newsletter immediately)
function askSubmitOnTplChange ( oSelectObject ) {
iOriginalTplIDArt = ' . $iTplIDArt . ' ;
if ( iOriginalTplIDArt != oSelectObject . options [ oSelectObject . selectedIndex ] . value ) {
if ( iOriginalTplIDArt == 0 ) {
// Everything fine: Just selecting a template for the first time
submitForm ();
} else {
// You may loose information, warn!
2021-04-26 18:28:43 +00:00
box . confirm ( " ' . i18n( " HTML newsletter template changed " , " cl - newsletter " ) . ' " , " ' . i18n( " HTML template has been changed . Do you like to save now to apply changes ? < br />< br />< b > Note , that existing HTML newsletter content will get lost !</ b > " , " cl - newsletter " ) . ' " , " submitForm() " );
2019-10-26 12:35:06 +00:00
}
}
}
function submitForm () {
document . frmNewsletterMsg . submit ();
}
</ script > ' ;
$oPage -> addScript ( 'messagebox' , '<script type="text/javascript" src="scripts/messageBox.js.php?contenido=' . $sess -> id . '"></script>' );
$oPage -> addScript ( 'execscript' , $sExecScript );
$oPage -> setContent ( $notis . $oForm -> render ( true ));
} else {
$oPage -> setContent ( $notis . " " );
}
$oPage -> render ();
?>