Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Tue, Nov 11, 2:30 AM

in-portal

Index: branches/unlabeled/unlabeled-1.28.2/core/units/languages/languages_event_handler.php
===================================================================
--- branches/unlabeled/unlabeled-1.28.2/core/units/languages/languages_event_handler.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.28.2/core/units/languages/languages_event_handler.php (revision 6793)
@@ -0,0 +1,438 @@
+<?php
+
+ class LanguagesEventHandler extends kDBEventHandler
+ {
+ /**
+ * Allows to override standart permission mapping
+ *
+ */
+ function mapPermissions()
+ {
+ parent::mapPermissions();
+ $permissions = Array(
+ 'OnChangeLanguage' => Array('self' => true),
+ 'OnSetPrimary' => Array('self' => 'advanced:set_primary|add|edit'),
+ 'OnImportLanguage' => Array('self' => 'advanced:import'),
+ 'OnImportProgress' => Array('self' => 'advanced:import'),
+ 'OnExportLanguage' => Array('self' => 'advanced:export'),
+ 'OnExportProgress' => Array('self' => 'advanced:export'),
+
+ );
+ $this->permMapping = array_merge($this->permMapping, $permissions);
+ }
+
+ /**
+ * Updates table structure on new language adding/removing language
+ *
+ * @param kEvent $event
+ */
+ function OnReflectMultiLingualFields($event)
+ {
+ $ml_helper =& $this->Application->recallObject('kMultiLanguageHelper');
+
+ $this->Application->UnitConfigReader->includeConfigFiles(MODULES_PATH); //make sure to re-read all configs
+ foreach ($this->Application->UnitConfigReader->configData as $prefix => $config_data) {
+ $ml_helper->createFields($prefix);
+ }
+ }
+
+ /**
+ * Allows to set selected language as primary
+ *
+ * @param kEvent $event
+ */
+ function OnSetPrimary(&$event)
+ {
+ if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1)) {
+ return;
+ }
+
+ $this->StoreSelectedIDs($event);
+ $ids = $this->getSelectedIDs($event);
+ if ($ids) {
+ $id = array_shift($ids);
+ $object =& $event->getObject( Array('skip_autoload' => true) );
+ $object->Load($id);
+ $object->setPrimary();
+ }
+ }
+
+ /**
+ * [HOOK] Reset primary status of other languages if we are saving primary language
+ *
+ * @param kEvent $event
+ */
+ function OnUpdatePrimary(&$event)
+ {
+ $object =& $event->getObject( Array('skip_autoload' => true) );
+ $object->SwitchToLive();
+
+ // set primary for each languages, that have this checkbox checked
+ $ids = explode(',', $event->MasterEvent->getEventParam('ids'));
+ foreach ($ids as $id) {
+ $object->Load($id);
+ if ($object->GetDBField('PrimaryLang')) {
+ $object->setPrimary();
+ }
+
+ }
+
+ // if no primary language left, then set primary last language (not to load again) from edited list
+ $sql = 'SELECT '.$object->IDField.'
+ FROM '.$object->TableName.'
+ WHERE PrimaryLang = 1';
+ $primary_language = $this->Conn->GetOne($sql);
+
+ if (!$primary_language) {
+ $object->setPrimary(false);
+ }
+ }
+
+
+ /**
+ * Occurse before updating item
+ *
+ * @param kEvent $event
+ * @access public
+ */
+ function OnBeforeItemUpdate(&$event)
+ {
+ $object =& $event->getObject();
+ $status_field = array_shift( $this->Application->getUnitOption($event->Prefix, 'StatusField') );
+
+ if ($object->GetDBField('PrimaryLang') == 1 && $object->GetDBField($status_field) == 0) {
+ $object->SetDBField($status_field, 1);
+ }
+ }
+
+ /**
+ * Shows only enabled languages on front
+ *
+ * @param kEvent $event
+ */
+ function SetCustomQuery(&$event)
+ {
+ if($event->Special == 'enabled')
+ {
+ $object =& $event->getObject();
+ $object->addFilter('enabled_filter', '%1$s.Enabled = 1');
+ }
+ }
+
+ /**
+ * Copy labels from another language
+ *
+ * @param kEvent $event
+ */
+ function OnCopyLabels(&$event)
+ {
+ $object =& $event->getObject();
+ $from_lang_id = $object->GetDBField('CopyFromLanguage');
+
+ if( ($event->MasterEvent->status == erSUCCESS) && $object->GetDBField('CopyLabels') == 1 && ($from_lang_id > 0) )
+ {
+ $lang_id = $object->GetID();
+
+ // 1. phrases import
+ $phrases_live = $this->Application->getUnitOption('phrases','TableName');
+ $phrases_temp = $this->Application->GetTempName($phrases_live);
+ $sql = 'INSERT INTO '.$phrases_temp.'
+ SELECT Phrase, Translation, PhraseType, 0-PhraseId, '.$lang_id.', '.adodb_mktime().', "", Module
+ FROM '.$phrases_live.'
+ WHERE LanguageId='.$from_lang_id;
+ $this->Conn->Query($sql);
+
+ // 2. events import
+ $em_table_live = $this->Application->getUnitOption('emailmessages','TableName');
+ $em_table_temp = $this->Application->GetTempName($em_table_live);
+
+ $sql = 'SELECT * FROM '.$em_table_live.' WHERE LanguageId = '.$from_lang_id;
+ $email_messages = $this->Conn->Query($sql);
+ if($email_messages)
+ {
+ $id = $this->Conn->GetOne('SELECT MIN(EmailMessageId) FROM '.$em_table_live);
+ if($id > 0) $id = 0;
+ $id--;
+
+ $sqls = Array();
+ foreach($email_messages as $email_message)
+ {
+ $sqls[] = $id.','.$this->Conn->qstr($email_message['Template']).','.$this->Conn->qstr($email_message['MessageType']).','.$lang_id.','.$email_message['EventId'];
+ $id--;
+ }
+ $sql = 'INSERT INTO '.$em_table_temp.'(EmailMessageId,Template,MessageType,LanguageId,EventId) VALUES ('.implode('),(',$sqls).')';
+ $this->Conn->Query($sql);
+ }
+
+ $object->SetDBField('CopyLabels', 0);
+ }
+ }
+
+ /**
+ * Prepare temp tables for creating new item
+ * but does not create it. Actual create is
+ * done in OnPreSaveCreated
+ *
+ * @param kEvent $event
+ */
+ function OnPreCreate(&$event)
+ {
+ parent::OnPreCreate($event);
+
+ $object =& $event->getObject();
+ $object->SetDBField('CopyLabels', 1);
+
+ $live_table = $this->Application->GetLiveName($object->TableName);
+ $primary_lang_id = $this->Conn->GetOne('SELECT '.$object->IDField.' FROM '.$live_table.' WHERE PrimaryLang = 1');
+
+ $object->SetDBField('CopyFromLanguage', $primary_lang_id);
+ }
+
+
+ function OnChangeLanguage(&$event)
+ {
+ $this->Application->SetVar('m_lang', $this->Application->GetVar('language'));
+
+ //$this->Application->LinkVar('language', 'm_lang');
+ }
+
+ /**
+ * Parse language XML file into temp tables and redirect to progress bar screen
+ *
+ * @param kEvent $event
+ */
+ function OnImportLanguage(&$event)
+ {
+ if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1)) {
+ return;
+ }
+
+ $items_info = $this->Application->GetVar('phrases_import');
+ if($items_info)
+ {
+ list($id,$field_values) = each($items_info);
+ $object =& $this->Application->recallObject('phrases.import', 'phrases', Array('skip_autoload' => true) );
+ $object->SetFieldsFromHash($field_values);
+
+ $filename = getArrayValue($field_values, 'LangFile', 'tmp_name');
+ if( filesize($filename) )
+ {
+ $modules = getArrayValue($field_values,'Module');
+ $lang_xml =& $this->Application->recallObject('LangXML');
+ $lang_xml->Parse($filename, $field_values['PhraseType'], $modules, $field_values['ImportOverwrite']);
+
+ $event->redirect = true;
+ $event->SetRedirectParams( Array('lang_event' => 'OnImportProgress', 'pass' => 'all,lang', 'mode'=>$field_values['ImportOverwrite']) );
+ }
+ else
+ {
+ $object =& $this->Application->recallObject('phrases.import');
+ $object->SetError('LangFile', 'la_empty_file', 'la_EmptyFile');
+ $event->redirect = false;
+ }
+ }
+ }
+
+ /**
+ * Copies imported from xml file from temp table to live table
+ *
+ * @param kEvent $event
+ */
+ function OnImportProgress(&$event)
+ {
+ define('IMPORT_BY', 300); // import this much records per step
+ $template_name = 'regional/languages_import_step2';
+
+ $import_mode = (int)$this->Application->GetVar('mode'); // 1 - overwrite existing phrases, 0 - don't overwrite existing phrases
+ $import_source = (int)$this->Application->GetVar('source');
+ $import_steps = Array(0 => 'lang', 1 => 'phrases', 2 => 'emailmessages', 3 => 'finish');
+
+ $key_fields = Array(0 => 'PackName', 1 => 'Phrase', 2 => 'EventId'); // by what field should we search record match
+
+ $import_titles = Array(0 => 'la_ImportingLanguages', 1 => 'la_ImportingPhrases', 2 => 'la_ImportingEmailEvents', 3 => 'la_Done');
+
+ // --- BEFORE ---
+ $import_prefix = $import_steps[$import_source];
+ $import_start = (int)$this->Application->GetVar('start');
+ $id_field = $this->Application->getUnitOption($import_prefix,'IDField');
+ $dst_table = $this->Application->getUnitOption($import_prefix,'TableName');
+ $src_table = $this->Application->GetTempName($dst_table);
+
+ $import_total = $this->Application->GetVar('total');
+ if(!$import_total) $import_total = $this->Conn->GetOne('SELECT COUNT(*) FROM '.$src_table);
+ // --- AFTER ---
+
+ if($import_start == $import_total)
+ {
+ $import_source++;
+ $import_prefix = $import_steps[$import_source];
+ if($import_prefix == 'finish')
+ {
+ $event->SetRedirectParam('opener','u');
+ return true;
+ }
+
+ $import_start = 0;
+ $id_field = $this->Application->getUnitOption($import_prefix,'IDField');
+ $dst_table = $this->Application->getUnitOption($import_prefix,'TableName');
+ $src_table = $this->Application->GetTempName($dst_table);
+ $import_total = $this->Conn->GetOne('SELECT COUNT(*) FROM '.$src_table);
+ }
+
+ if($import_total > 0)
+ {
+ $done_percent = ($import_start * 100) / $import_total;
+ }
+ else
+ {
+ $done_percent = 100;
+ }
+
+ $block_params = Array( 'name' => $template_name,
+ 'title' => $import_titles[$import_source],
+ 'percent_done' => $done_percent,
+ 'percent_left' => 100 - $done_percent);
+
+ $this->Application->InitParser();
+ $this->Application->setUnitOption('phrases','AutoLoad',false);
+ echo $this->Application->ParseBlock($block_params);
+
+ //break out of buffering
+ $buffer_content = Array();
+ while (ob_get_level()) {
+ $buffer_content[] = ob_get_clean();
+ }
+ $ret = implode('', array_reverse($buffer_content));
+ echo $ret;
+ flush();
+
+
+ $sql = 'SELECT * FROM %s LIMIT %s,%s';
+ $rows = $this->Conn->Query( sprintf($sql,$src_table,$import_start,IMPORT_BY) );
+
+ $values_sql = '';
+
+ // if found and mode = 1 (overwrite)
+ $search_sql = 'SELECT '.$id_field.' FROM '.$dst_table.' WHERE '.$key_fields[$import_source].' = %s AND LanguageId = %s';
+ $update_sql = 'UPDATE '.$dst_table.' SET %s WHERE '.$id_field.' = %s';
+
+ foreach($rows as $row)
+ {
+ $tmp_sql = sprintf($search_sql, $this->Conn->qstr($row[ $key_fields[$import_source] ]), $row['LanguageId'] );
+ $tmp_id = $this->Conn->GetOne($tmp_sql);
+ if($tmp_id > 0 && $import_mode == 1)
+ {
+ // update
+ $update_fields = '';
+ foreach($row as $field_name => $field_value)
+ {
+ if($field_name == $id_field) continue;
+ $update_fields .= '`'.$field_name.'` = '.$this->Conn->qstr($field_value).',';
+ }
+ $update_fields = preg_replace('/(.*),$/', '\\1', $update_fields);
+ $this->Conn->Query( sprintf($update_sql, $update_fields, $tmp_id) );
+ }
+ elseif(!$tmp_id)
+ {
+ $values_sql .= '(';
+ foreach($row as $field_value)
+ {
+ $values_sql .= $this->Conn->qstr($field_value).',';
+ }
+ $values_sql = preg_replace('/(.*),$/', '\\1', $values_sql).'),';
+ }
+ }
+
+ if($values_sql)
+ {
+ $fields_sql = '';
+ $fields = array_keys( $this->Application->getUnitOption($import_prefix,'Fields') );
+ foreach($fields as $field_name)
+ {
+ $fields_sql .= '`'.$field_name.'`,';
+ }
+ $fields_sql = preg_replace('/(.*),$/', '\\1', $fields_sql);
+
+ $values_sql = preg_replace('/(.*),$/', '\\1', $values_sql);
+ $sql = sprintf('INSERT INTO %s (%s) VALUES %s', $dst_table, $fields_sql, $values_sql);
+ $this->Conn->Query($sql);
+ }
+ $event->setRedirectParams( Array('lang_event' => 'OnImportProgress', 'pass' => 'all,lang', 'start' => $import_start += count($rows), 'total' => $import_total, 'source' => $import_source, 'mode' => $import_mode) );
+ }
+
+ /**
+ * Stores ids of selected languages and redirects to export language step 1
+ *
+ * @param kEvent $event
+ */
+ function OnExportLanguage(&$event)
+ {
+ if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1)) {
+ return;
+ }
+
+ $this->Application->setUnitOption('phrases','AutoLoad',false);
+
+ $this->StoreSelectedIDs($event);
+ $this->Application->StoreVar('export_language_ids', implode(',', $this->getSelectedIDs($event)) );
+
+ $event->setRedirectParams( Array('m_opener'=>'d','phrases.export_event'=>'OnNew','pass'=>'all,phrases.export') );
+ $event->redirect = 'regional/languages_export';
+ }
+
+ /**
+ * Saves selected languages to xml file passed
+ *
+ * @param kEvent $event
+ */
+ function OnExportProgress(&$event)
+ {
+ $items_info = $this->Application->GetVar('phrases_export');
+ if($items_info)
+ {
+ list($id,$field_values) = each($items_info);
+ $object =& $this->Application->recallObject('phrases.export', 'phrases', Array('skip_autoload' => true) );
+ $object->SetFieldsFromHash($field_values);
+
+ $lang_ids = explode(',', $this->Application->RecallVar('export_language_ids') );
+
+ if( !getArrayValue($field_values,'LangFile') )
+ {
+ $object->SetError('LangFile', 'required');
+ $event->redirect = false;
+ return false;
+ }
+ if( !is_writable(EXPORT_PATH) )
+ {
+ $object->SetError('LangFile', 'write_error', 'la_ExportFolderNotWritable');
+ $event->redirect = false;
+ return false;
+ }
+ if( substr($field_values['LangFile'], -5) != '.lang' ) $field_values['LangFile'] .= '.lang';
+ $filename = EXPORT_PATH.'/'.$field_values['LangFile'];
+
+ $lang_xml =& $this->Application->recallObject('LangXML');
+ if ($object->GetDBField('DoNotEncode')) {
+ $lang_xml->SetEncoding('plain');
+ }
+ $lang_xml->Create($filename, $field_values['PhraseType'], $lang_ids, $field_values['Module']);
+
+ }
+
+ $event->redirect = 'regional/languages_export_step2';
+ $event->SetRedirectParam('export_file', $field_values['LangFile']);
+ }
+
+ /**
+ * Returns to previous template in opener stack
+ *
+ * @param kEvent $event
+ */
+ function OnGoBack(&$event)
+ {
+ $event->redirect_params['opener'] = 'u';
+ }
+
+ }
+
+?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.28.2/core/units/languages/languages_event_handler.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.28
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: branches/unlabeled/unlabeled-1.28.2/core/units/email_events/email_events_event_handler.php
===================================================================
--- branches/unlabeled/unlabeled-1.28.2/core/units/email_events/email_events_event_handler.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.28.2/core/units/email_events/email_events_event_handler.php (revision 6793)
@@ -0,0 +1,273 @@
+<?php
+
+ class EmailEventsEventsHandler extends kDBEventHandler
+ {
+
+ /**
+ * Allows to override standart permission mapping
+ *
+ */
+ function mapPermissions()
+ {
+ parent::mapPermissions();
+ $permissions = Array(
+ 'OnFrontOnly' => Array('self' => 'edit'),
+ 'OnSaveSelected' => Array('self' => 'view'),
+ );
+ $this->permMapping = array_merge($this->permMapping, $permissions);
+ }
+
+ /**
+ * Changes permission section to one from REQUEST, not from config
+ *
+ * @param kEvent $event
+ */
+ function CheckPermission(&$event)
+ {
+ $module = $this->Application->GetVar('module');
+ $module = explode(':', $module, 2);
+
+ if (count($module) == 1) {
+ $main_prefix = $this->Application->findModule('Name', $module[0], 'Var');
+ }
+ else {
+ $exceptions = Array('Category' => 'c', 'Users' => 'u');
+ $main_prefix = $exceptions[ $module[1] ];
+ }
+ $section = $this->Application->getUnitOption($main_prefix.'.email', 'PermSection');
+
+ $event->setEventParam('PermSection', $section);
+ return parent::CheckPermission($event);
+ }
+
+ /**
+ * Apply any custom changes to list's sql query
+ *
+ * @param kEvent $event
+ * @access protected
+ * @see OnListBuild
+ */
+ function SetCustomQuery(&$event)
+ {
+ if ($event->Special == 'module') {
+ $object =& $event->getObject();
+ $module = $this->Application->GetVar('module');
+ $object->addFilter('module_filter', '%1$s.Module = '.$this->Conn->qstr($module));
+ }
+ }
+
+ /**
+ * Sets status Front-End Only to selected email events
+ *
+ * @param kEvent $event
+ */
+ function OnFrontOnly(&$event)
+ {
+ $ids = implode(',', $this->StoreSelectedIDs($event));
+
+ $table_name = $this->Application->getUnitOption($event->Prefix, 'TableName');
+ $sql = 'UPDATE '.$table_name.'
+ SET Enabled = 2
+ WHERE EventId IN ('.$ids.')';
+ $this->Conn->Query($sql);
+ }
+
+ /**
+ * Sets selected user to email events selected
+ *
+ * @param kEvent $event
+ */
+ function OnSelectUser(&$event)
+ {
+ $items_info = $this->Application->GetVar('u');
+ if ($items_info) {
+ $user_id = array_shift( array_keys($items_info) );
+
+ $ids = $this->Application->RecallVar($event->getPrefixSpecial().'_selected_ids');
+ $id_field = $this->Application->getUnitOption($event->Prefix, 'IDField');
+ $table_name = $this->Application->getUnitOption($event->Prefix, 'TableName');
+ $sql = 'UPDATE '.$table_name.'
+ SET '.$this->Application->RecallVar('dst_field').' = '.$user_id.'
+ WHERE '.$id_field.' IN ('.$ids.')';
+ $this->Conn->Query($sql);
+ }
+
+ $this->finalizePopup($event);
+ }
+
+ /**
+ * Saves selected ids to session
+ *
+ * @param kEvent $event
+ */
+ function OnSaveSelected(&$event)
+ {
+ $this->StoreSelectedIDs($event);
+ }
+
+ /**
+ * Raised when email message shoul be sent
+ *
+ * @param kEvent $event
+ */
+ function OnEmailEvent(&$event){
+
+ $email_event = $event->getEventParam('EmailEventName');
+ if( strpos($email_event, '_') !== false )
+ {
+ trigger_error('<span class="debug_error">Invalid email event name</span> <b>'.$email_event.'</b>. Use only <b>UPPERCASE characters</b> and <b>dots</b> as email event names', E_USER_ERROR);
+ }
+
+ $to_user_id = $event->getEventParam('EmailEventToUserId');
+ $email_event_type = $event->getEventParam('EmailEventType');
+
+ $message_object = &$this->Application->recallObject('emailmessages', null, Array('skip_autoload' => true));
+ $event_table = $this->Application->getUnitOption('emailevents', 'TableName');
+
+ $event_object =& $event->getObject( Array('skip_autoload' => true) );
+ $event_object->Load(array('Event'=>$email_event, 'Type'=>$email_event_type));
+
+ $event_id = $event_object->GetDBField('EventId');
+ $from_user_id = $event_object->GetDBField('FromUserId');
+ $type = $event_object->GetDBField('Type');
+ $enabled = $event_object->GetDBField('Enabled');
+
+ $direct_send_params = $event->getEventParam('DirectSendParams');
+
+ if ($enabled == 0) return; // disabled event
+ if ($enabled == 2 && $this->Application->IsAdmin() ) return; // event only for front-end
+
+ if ($type == 1){
+ // For type "Admin" recipient is a user from field FromUserId which means From/To user in Email events list
+ $to_user_id = $from_user_id;
+ $from_user_id = -1;
+ }
+ /*
+ if (!($to_user_id > 0) && !$direct_send_params){
+ // if we can not determine recepient we will not send email
+ return;
+ }
+ */
+ //Parse Message Template
+ $message_object->Load(array('EventId' => $event_id, 'LanguageId' => $this->Application->GetVar('m_lang')));
+ $message_type = $message_object->GetDBField('MessageType');
+
+ $email_object = &$this->Application->recallObject('kEmailMessage');
+ $email_object->Clear();
+
+ // add footer: begin
+ $sql = 'SELECT em.Template
+ FROM '.$message_object->TableName.' em
+ LEFT JOIN '.TABLE_PREFIX.'Events e ON e.EventId = em.EventId
+ WHERE em.LanguageId = '.$message_object->GetDBField('LanguageId').' AND e.Event = "COMMON.FOOTER"';
+ $footer = explode("\n\n", $this->Conn->GetOne($sql));
+ $footer = $message_object->GetDBField('MessageType') == 'text' ? $email_object->convertHTMLtoPlain($footer[1]) : $footer[1];
+ $message_template = $message_object->GetDBField('Template')."\r\n".$footer;
+ // add footer: end
+
+ $from_user_object = &$this->Application->recallObject('u.email-from', null, Array('skip_autoload' => true));
+ $from_user_object->Load($from_user_id);
+ // here if we don't have from_user loaded, it takes a default user from config values
+ if ( $from_user_object->IsLoaded() ) {
+ $from_user_email = $from_user_object->GetDBField('Email');
+ $from_user_name = trim($from_user_object->GetDBField('FirstName').' '.$from_user_object->GetDBField('LastName'));
+ }
+ else {
+ $from_user_email = $this->Application->ConfigValue('Smtp_AdminMailFrom');
+ }
+
+ $to_user_object = &$this->Application->recallObject('u.email-to', null, Array('skip_autoload' => true));
+ $to_user_object->Load($to_user_id);
+ $to_user_email = $to_user_object->GetDBField('Email');
+ $to_user_name = trim($to_user_object->GetDBField('FirstName').' '.$to_user_object->GetDBField('LastName'));
+
+ if($direct_send_params){
+ $to_user_email = ( $direct_send_params['to_email'] ? $direct_send_params['to_email'] : $to_user_email );
+ $to_user_name = ( $direct_send_params['to_name'] ? $direct_send_params['to_name'] : $to_user_name );
+ $from_user_email = ( $direct_send_params['from_email'] ? $direct_send_params['from_email'] : $from_user_email);
+ $from_user_name = ( $direct_send_params['from_name'] ? $direct_send_params['from_name'] : $from_user_name );
+ $message_body_additional = $direct_send_params['message'];
+ }
+
+ $to_user_email = $to_user_email ? $to_user_email : $this->Application->ConfigValue('Smtp_AdminMailFrom');
+
+ $this->Application->makeClass('Template');
+ $this->Application->InitParser();
+ $parser_params = $this->Application->Parser->Params;
+ $direct_send_params['message_text'] = $message_body_additional;
+ $this->Application->Parser->Params = array_merge_recursive2($this->Application->Parser->Params, $direct_send_params);
+ $message_template = str_replace('<inp:touser _Field="password"', '<inp2:u_Field name="Password_plain"', $message_template);
+ $message_template = str_replace('<inp:touser _Field="UserName"', '<inp2:u_Field name="Login"', $message_template);
+ $message_template = str_replace('<inp:touser _Field', '<inp2:u_Field name', $message_template);
+ $message_template = $this->Application->Parser->Parse($message_template, 'email_template', 0);
+ $this->Application->Parser->Params = $parser_params;
+
+ $message_template = str_replace("\r", "", $message_template);
+
+ list($message_headers, $message_body) = explode("\n\n", $message_template, 2);
+
+
+ $email_object->setFrom($from_user_email, $from_user_name);
+ $email_object->setTo($to_user_email, $to_user_name);
+ $email_object->setSubject('Mail message');
+
+ $email_object->setHeaders($message_headers);
+
+ if ($message_type == 'html'){
+ $email_object->setHTMLBody($message_body);
+ }
+ else {
+ $email_object->setTextBody($message_body);
+ }
+
+ $smtp_object = &$this->Application->recallObject('kSmtpClient');
+ $smtp_object->debug = $this->Application->isDebugMode() && constOn('DBG_SMTP');
+
+ $smtp_server = $this->Application->ConfigValue('Smtp_Server');
+ $smtp_port = $this->Application->ConfigValue('Smtp_Port');
+
+ $smtp_authenticate = $this->Application->ConfigValue('Smtp_Authenticate');
+ if ($smtp_authenticate){
+ $smtp_user = $this->Application->ConfigValue('Smtp_User');
+ $smtp_pass = $this->Application->ConfigValue('Smtp_Pass');
+ }else{
+ $smtp_user = '';
+ $smtp_pass = '';
+ }
+
+
+ if ($smtp_server){
+ if ($email_object->sendSMTP($smtp_object, $smtp_server, $smtp_user, $smtp_pass, $smtp_authenticate)){
+ $event->status=erSUCCESS;
+ }
+ else {
+ $event->status=erFAIL;
+ }
+ }else{
+ if($email_object->send()){
+ $event->status=erSUCCESS;
+ }
+ else {
+ $event->status=erFAIL;
+ }
+ }
+
+ if ($event->status == erSUCCESS){
+ if (!$from_user_name) {
+ $from_user_name = strip_tags( $this->Application->ConfigValue('Site_Name') );
+ }
+ $sql = 'INSERT INTO '.TABLE_PREFIX.'EmailLog SET
+ fromuser = '.$this->Conn->qstr($from_user_name.' ('.$from_user_email.')').',
+ addressto = '.$this->Conn->qstr($to_user_name.' ('.$to_user_email.')').',
+ subject = '.$this->Conn->qstr($email_object->Subject).',
+ timestamp = UNIX_TIMESTAMP(),
+ event = '.$this->Conn->qstr($email_event);
+ $this->Conn->Query($sql);
+ }
+
+ $this->Application->removeObject('u.email-from');
+ $this->Application->removeObject('u.email-to');
+ return $event;
+ }
+ }
+?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.28.2/core/units/email_events/email_events_event_handler.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.28
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property

Event Timeline