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 . recipients_import . php 128 2019 - 07 - 03 11 : 58 : 28 Z oldperl $ :
* }}
*
*/
if ( ! defined ( 'CON_FRAMEWORK' )) {
die ( 'Illegal call' );
}
$oPage = new cPage ;
$oRecipients = new RecipientCollection ;
if ( is_array ( $cfg [ 'plugins' ][ 'recipients' ])) {
foreach ( $cfg [ 'plugins' ][ 'recipients' ] as $plugin ) {
plugin_include ( " recipients " , $plugin . " / " . $plugin . " .php " );
}
}
// Check form data
if ( $_REQUEST [ " selDelimiter " ] == " " ) {
$_REQUEST [ " selDelimiter " ] = " tab " ;
}
$aFields = array ();
$aFieldDetails = array ();
2021-04-26 18:28:43 +00:00
$aFields [ " name " ] = strtolower ( i18n ( " Name " , " cl-newsletter " ));
2019-10-26 12:35:06 +00:00
$aFieldDetails [ " name " ][ " fieldtype " ] = " field " ; // field, plugin or group
$aFieldDetails [ " name " ][ " mandatory " ] = false ; // true or false
$aFieldDetails [ " name " ][ " type " ] = " string " ; // string, boolean or date
$aFieldDetails [ " name " ][ " link " ] = false ; // plugin name for plugins, recipient group id for groups
$aFieldDetails [ " name " ][ " col " ] = - 1 ; // Stores column index where this field has been found
2021-04-26 18:28:43 +00:00
$aFields [ " email " ] = strtolower ( i18n ( " Mail " , " cl-newsletter " ));
2019-10-26 12:35:06 +00:00
$aFieldDetails [ " email " ][ " fieldtype " ] = " field " ;
$aFieldDetails [ " email " ][ " mandatory " ] = true ;
$aFieldDetails [ " email " ][ " type " ] = " string " ;
$aFieldDetails [ " email " ][ " link " ] = false ;
$aFieldDetails [ " email " ][ " col " ] = - 1 ;
2021-04-26 18:28:43 +00:00
$aFields [ " deactivated " ] = strtolower ( i18n ( " Deactivated " , " cl-newsletter " ));
2019-10-26 12:35:06 +00:00
$aFieldDetails [ " deactivated " ][ " fieldtype " ] = " field " ;
$aFieldDetails [ " deactivated " ][ " mandatory " ] = false ;
$aFieldDetails [ " deactivated " ][ " type " ] = " boolean " ;
$aFieldDetails [ " deactivated " ][ " link " ] = false ;
$aFieldDetails [ " deactivated " ][ " col " ] = - 1 ;
2021-04-26 18:28:43 +00:00
$aFields [ " confirmed " ] = strtolower ( i18n ( " Confirmed " , " cl-newsletter " ));
2019-10-26 12:35:06 +00:00
$aFieldDetails [ " confirmed " ][ " fieldtype " ] = " field " ;
$aFieldDetails [ " confirmed " ][ " mandatory " ] = false ;
$aFieldDetails [ " confirmed " ][ " type " ] = " boolean " ;
$aFieldDetails [ " confirmed " ][ " link " ] = false ;
$aFieldDetails [ " confirmed " ][ " col " ] = - 1 ;
2021-04-26 18:28:43 +00:00
$aFields [ " confirmeddate " ] = strtolower ( i18n ( " Confirmed Date " , " cl-newsletter " ));
2019-10-26 12:35:06 +00:00
$aFieldDetails [ " confirmeddate " ][ " fieldtype " ] = " field " ;
$aFieldDetails [ " confirmeddate " ][ " mandatory " ] = false ;
$aFieldDetails [ " confirmeddate " ][ " type " ] = " date " ;
$aFieldDetails [ " confirmeddate " ][ " link " ] = false ;
$aFieldDetails [ " confirmeddate " ][ " col " ] = - 1 ;
2021-04-26 18:28:43 +00:00
$aFields [ " news_type " ] = strtolower ( i18n ( " Message type " , " cl-newsletter " ));
2019-10-26 12:35:06 +00:00
$aFieldDetails [ " news_type " ][ " fieldtype " ] = " field " ;
$aFieldDetails [ " news_type " ][ " mandatory " ] = false ;
$aFieldDetails [ " news_type " ][ " type " ] = " boolean " ;
$aFieldDetails [ " news_type " ][ " link " ] = false ;
$aFieldDetails [ " news_type " ][ " col " ] = - 1 ;
// Check out if there are any plugins
if ( is_array ( $cfg [ 'plugins' ][ 'recipients' ])) {
foreach ( $cfg [ 'plugins' ][ 'recipients' ] as $sPlugin ) {
if ( function_exists ( " recipients_ " . $sPlugin . " _wantedVariables " ) && function_exists ( " recipients_ " . $sPlugin . " _canonicalVariables " )) {
$aPluginTitles = call_user_func ( " recipients_ " . $sPlugin . " _canonicalVariables " );
$aPluginFields = call_user_func ( " recipients_ " . $sPlugin . " _wantedVariables " );
foreach ( $aPluginFields as $sField ) {
//if ($_REQUEST["ckb".$sField]) {
$aFields [ $sField ] = strtolower ( str_replace ( " " , " " , $aPluginTitles [ $sField ]));
$aFieldDetails [ $sField ][ " fieldtype " ] = " plugin " ;
$aFieldDetails [ $sField ][ " mandatory " ] = false ;
$aFieldDetails [ $sField ][ " type " ] = " string " ;
$aFieldDetails [ $sField ][ " link " ] = $sPlugin ;
$aFieldDetails [ $sField ][ " col " ] = - 1 ;
//}
}
}
}
}
// Get groups
$oRcpGroups = new RecipientGroupCollection ;
$oRcpGroups -> setWhere ( " idclient " , $client );
$oRcpGroups -> setWhere ( " idlang " , $lang );
$oRcpGroups -> setOrder ( " groupname " );
$oRcpGroups -> query ();
while ( $oRcpGroup = $oRcpGroups -> next ()) {
$sField = " g " . $oRcpGroup -> get ( $oRcpGroup -> primaryKey );
$sGroupName = $oRcpGroup -> get ( " groupname " );
$sGroupName = str_replace ( " " , " " , $sGroupName );
$sGroupName = str_replace ( " \t " , " " , $sGroupName );
$sGroupName = str_replace ( " \n " , " " , $sGroupName );
$sGroupName = str_replace ( " \r " , " " , $sGroupName );
$sGroupName = str_replace ( " \0 " , " " , $sGroupName );
$sGroupName = str_replace ( " \x0B ; " , " " , $sGroupName );
// Only PHP5!
//$sGroupName = str_replace(str_split(" \t\n\r\0\x0B;"), "", $oRcpGroup->get("groupname"));
2021-04-26 18:28:43 +00:00
$aFields [ $sField ] = strtolower ( clHtmlEntities ( trim ( i18n ( " Group " , " cl-newsletter " ) . " _ " . $sGroupName )));
2019-10-26 12:35:06 +00:00
$aFieldDetails [ $sField ][ " fieldtype " ] = " group " ;
$aFieldDetails [ $sField ][ " mandatory " ] = false ;
$aFieldDetails [ $sField ][ " type " ] = " string " ;
$aFieldDetails [ $sField ][ " link " ] = $oRcpGroup -> get ( $oRcpGroup -> primaryKey );
$aFieldDetails [ $sField ][ " col " ] = - 1 ;
}
if ( $action == " recipients_import_exec " && $perm -> have_perm_area_action ( " recipients " , " recipients_create " )) {
$_REQUEST [ " txtData " ] = trim ( stripslashes ( $_REQUEST [ " txtData " ]));
if ( $_REQUEST [ " txtData " ]) {
switch ( $_REQUEST [ " selDelimiter " ]) {
case " semicolon " :
$sDelimiter = " ; " ;
break ;
default :
$sDelimiter = " \t " ; //chr(9);
}
//echo "<pre>".nl2br(stripslashes($_REQUEST["txtData"]))."</pre>";
$aLines = explode ( " \n " , stripslashes ( $_REQUEST [ " txtData " ]));
$iAdded = 0 ;
$iDublettes = 0 ;
$iInvalid = 0 ;
$iRow = 0 ;
$iCol = 0 ;
$bStop = false ;
$sMessage = " " ;
$aMessage = array ();
$aInvalidLines = array ();
$oGroupMembers = new RecipientGroupMemberCollection ;
foreach ( $aLines as $sLine ) {
$iRow ++ ;
$aParts = explode ( $sDelimiter , trim ( $sLine ));
if ( $iRow == 1 ) {
$aInvalidLines [] = $sLine ;
foreach ( $aParts as $sHeader ) {
$sKey = array_search ( strtolower ( clHtmlEntities ( trim ( $sHeader ))), $aFields );
if ( $sKey === false ) {
2021-04-26 18:28:43 +00:00
$aMessage [] = sprintf ( i18n ( " Given column header '%s' unknown, column ignored " , " cl-newsletter " ), $sHeader );
2019-10-26 12:35:06 +00:00
} else {
$aFieldDetails [ $sKey ][ " col " ] = $iCol ;
$iCol ++ ;
}
}
foreach ( $aFieldDetails as $sKey => $aDetails ) {
if ( $aDetails [ " mandatory " ] && $aDetails [ " col " ] == - 1 ) {
2021-04-26 18:28:43 +00:00
$aMessage [] = sprintf ( i18n ( " Mandatory column '%s' wasn't found, import stopped " , " cl-newsletter " ), $aDetails [ $sKey ]);
2019-10-26 12:35:06 +00:00
$bStop = true ;
}
}
if ( $bStop ) {
exit ;
} else {
$_REQUEST [ " txtData " ] = " " ;
}
} else {
$sEMail = trim ( $aParts [ $aFieldDetails [ " email " ][ " col " ]]);
if ( $aFieldDetails [ " name " ][ " col " ] > - 1 ) {
$sName = trim ( $aParts [ $aFieldDetails [ " name " ][ " col " ]]);
if ( $sName == " " ) {
$sName = $sEMail ;
}
} else {
$sName = $sEMail ;
}
if ( $sEMail == " " ) {
2021-04-26 18:28:43 +00:00
$aMessage [] = sprintf ( i18n ( " Item with empty mail address found, item ignored (name: %s, row: %s) " , " cl-newsletter " ), $sName , $iRow );
2019-10-26 12:35:06 +00:00
$aInvalidLines [] = $sLine ;
$iInvalid ++ ;
} else if ( ! isValidMail ( $sEMail )) {
2021-04-26 18:28:43 +00:00
$aMessage [] = sprintf ( i18n ( " Mail address '%s' is invalid, item ignored (row: %s) " , " cl-newsletter " ), $sEMail , $iRow );
2019-10-26 12:35:06 +00:00
$aInvalidLines [] = $sLine ;
$iInvalid ++ ;
} else if ( $oRecipients -> emailExists ( $sEMail )) {
2021-04-26 18:28:43 +00:00
$aMessage [] = sprintf ( i18n ( " Recipient with mail address '%s' already exists, item skipped (row: %s) " , " cl-newsletter " ), $sEMail , $iRow );
2019-10-26 12:35:06 +00:00
$aInvalidLines [] = $sLine ;
$iDublettes ++ ;
} else {
unset ( $sLine );
// Must be $recipient for plugins
if ( $recipient = $oRecipients -> create ( $sEMail , $sName )) {
$iID = $recipient -> get ( $recipient -> primaryKey );
$iAdded ++ ;
unset ( $aPluginValue );
$aPluginValue = array ();
foreach ( $aFieldDetails as $sKey => $aDetails ) {
if ( $aDetails [ " col " ] > - 1 ) {
switch ( $aDetails [ " fieldtype " ]) {
case " field " :
switch ( $aDetails [ " type " ]) {
case " boolean " :
$sValue = strtolower ( trim ( $aParts [ $aDetails [ " col " ]]));
// html is only treated as "true", to get html messages for recipients
// - quick and dirty...
2021-04-26 18:28:43 +00:00
if ( $sValue == " yes " || $sValue == i18n ( " yes " , " cl-newsletter " ) || $sValue == " true " ||
2019-10-26 12:35:06 +00:00
( is_numeric ( $sValue ) && $sValue > 0 ) ||
$sValue == " html " ) {
$recipient -> set ( $sKey , 1 );
if ( $sKey == " confirmed " ) {
// Ensure, that if a recipient is confirmed, a confirmed date
// is available. As "confirmeddate" will be set after "confirmed"
// a specified confirmeddate will overwrite this default
$recipient -> set ( " confirmeddate " , date ( " Y-m-d H:i:s " ), false );
}
} else {
$recipient -> set ( $sKey , 0 );
}
break ;
case " date " :
// TODO: Check conversion: Result may be unpredictable...
$sValue = trim ( $aParts [ $aDetails [ " col " ]]);
$recipient -> set ( $sKey , date ( " Y-m-d H:i:s " , strtotime ( $sValue )), false );
break ;
default :
$sValue = trim ( $aParts [ $aDetails [ " col " ]]);
$recipient -> set ( $sKey , $sValue );
}
break ;
case " plugin " :
// type may be mentioned here, also, but as plugins currently can't
// specify the type, just treat everything as string
// There may be plugins which store more than one value per plugin_store-
// function. As the plugin_store parameter is an array of values, collect
// all values in an array for later storing... unfortunately, that means,
// that we have to go through the fields array second time per item *sigh*
$aPluginValue [ $aDetails [ " link " ]][ $sKey ] = trim ( $aParts [ $aDetails [ " col " ]]);
break ;
case " group " :
// Add recipient to group
$sValue = strtolower ( trim ( $aParts [ $aDetails [ " col " ]]));
2021-04-26 18:28:43 +00:00
if ( $sValue == " yes " || $sValue == i18n ( " yes " , " cl-newsletter " ) ||
2019-10-26 12:35:06 +00:00
$sValue == " true " || ( is_numeric ( $sValue ) && $sValue > 0 )) {
$oGroupMembers -> create ( $aDetails [ " link " ], $iID );
}
break ;
}
}
}
// Store all base data
$recipient -> store ();
// Store plugin data (to store plugin data, only, where the column has been found in the data
// should be faster than going through all plugins and store mostly empty arrays)
$sCurrentPlugin = " " ;
foreach ( $aFieldDetails as $sKey => $aDetails ) {
if ( $aDetails [ " col " ] > - 1 &&
$aDetails [ " fieldtype " ] == " plugin " &&
$aDetails [ " link " ] !== $sCurrentPlugin ) {
$sCurrentPlugin = $aDetails [ " link " ];
call_user_func ( " recipients_ " . $sCurrentPlugin . " _store " , $aPluginValue [ $sCurrentPlugin ]);
}
}
}
}
}
}
if ( count ( $aInvalidLines ) > 1 ) {
$_REQUEST [ " txtData " ] = implode ( " \n " , $aInvalidLines );
}
if ( count ( $aMessage ) > 0 ) {
$sMessage = $notification -> returnNotification ( " warning " , implode ( " <br /> " , $aMessage )) . " <br /> " ;
}
2021-04-26 18:28:43 +00:00
$sMessage .= $notification -> returnNotification ( " info " , sprintf ( i18n ( " %d recipients added, %d recipients skipped (email already exists) and %d invalid recipients/e-mail adresses ignored. Invalid recipients are shown (if any). " , " cl-newsletter " ), $iAdded , $iDublettes , $iInvalid ));
2019-10-26 12:35:06 +00:00
if ( $iAdded > 0 ) {
$oPage -> setReload ();
}
}
}
$oForm = new UI_Table_Form ( " properties " );
$oForm -> setVar ( " frame " , $frame );
$oForm -> setVar ( " area " , $area );
$oForm -> setVar ( " action " , " recipients_import_exec " );
2021-04-26 18:28:43 +00:00
$oForm -> addHeader ( i18n ( " Import recipients " , " cl-newsletter " ));
2019-10-26 12:35:06 +00:00
$oSelDelimiter = new cHTMLSelectElement ( " selDelimiter " );
$aItems = array ();
2021-04-26 18:28:43 +00:00
$aItems [] = array ( " tab " , i18n ( " Tab " , " cl-newsletter " ));
$aItems [] = array ( " semicolon " , i18n ( " Semicolon " , " cl-newsletter " ));
2019-10-26 12:35:06 +00:00
$oSelDelimiter -> autoFill ( $aItems );
$oSelDelimiter -> setDefault ( $_REQUEST [ " selDelimiter " ]);
2021-04-26 18:28:43 +00:00
$oForm -> add ( i18n ( " Delimiter " , " cl-newsletter " ), $oSelDelimiter -> render ());
2019-10-26 12:35:06 +00:00
$oAreaData = new cHTMLTextarea ( " txtData " , $_REQUEST [ " txtData " ], 80 , 20 );
2021-04-26 18:28:43 +00:00
$sInfo = '<a href="javascript:fncShowHide(\'idInfoText\');"><strong>' . i18n ( " Import information " , " cl-newsletter " ) . '</strong></a>' .
2019-10-26 12:35:06 +00:00
'<div id="idInfoText" style="display: none">' .
2021-04-26 18:28:43 +00:00
'<br /><br /><strong>' . i18n ( " Specify colum types: " , " cl-newsletter " ) . '</strong>' .
i18n ( " <br />The first line must contain the column names; this specifies the column order.<br /><column name>[delimiter]<column name>... " , " cl-newsletter " ) .
'<br /><br /><strong>' . i18n ( " Data structure: " , " cl-newsletter " ) . '</strong><br />' .
i18n ( " The recipients have to be entered using the following format:<br /><data>[Delimiter]<data>... - each recipient in a new line. " , " cl-newsletter " ) .
'<br /><br /><strong>' . i18n ( " Example: " , " cl-newsletter " ) . '</strong>' .
i18n ( " <br />name;mail;confirmed<br />Smith;jon.smith@example.org;1 " , " cl-newsletter " ) .
'<br /><br /><strong>' . i18n ( " The following column names will be recognized: " , " cl-newsletter " ) . '</strong><br />' .
2019-10-26 12:35:06 +00:00
implode ( " <br /> \n " , $aFields );
2021-04-26 18:28:43 +00:00
$oForm -> add ( i18n ( " Recipients " , " cl-newsletter " ), $oAreaData -> render () . " <br /> " . $sInfo );
2019-10-26 12:35:06 +00:00
unset ( $sInfo );
$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 " ;
}
}
</ script > ' ;
$oPage -> addScript ( 'execscript' , $sExecScript );
$oPage -> setContent ( $sMessage . $oForm -> render ( true ));
$oPage -> render ();
?>