Дипломная работа: Автоматизация процесса управления взаимоотношениями с клиентами в компании "Фаворит"

Внимание! Если размещение файла нарушает Ваши авторские права, то обязательно сообщите нам
112
*
* @var string
*
*/
public $UsersTable;
/**
* Поле с именем получателя
*
* @var string
*
*/
public $NameField;
/**
* Поле с адресом получателя
*
* @var string
*
*/
public $MailField;
protected $RecipientsForm;
public function __construct($_name, $_parent, $_users_table="",
$_name_field="",
$_mail_field="")
{
parent::__construct($_name, $_parent);
$this->UsersTable=$_users_table;
$this->NameField=$_name_field;
$this->MailField=$_mail_field;
$this-
>CreateFromXML(ProjectPath()."forms/mail_sender/LayoutOFormMailsender.xm
l");
$this->RecipientsForm=new OFormRecipients("mailer_recipients", $this,
$_users_table,
$_name_field, $_mail_field);
$this->RecipientsForm->ReturnToEdit="Edit_TO";
$this->IconSrc="images/icons/wand__plus.png";
}
protected function BeforeGenerate()
{
parent::BeforeGenerate();
$this->FillListBoxTemplates();
}
public function Work()
{
$this->ShowModal();
}
protected function ButtonAddRecipients_OnClick()
{
113
$this->RecipientsForm->SetCenterPosition();
$this->RecipientsForm->ShowModal();
}
protected function FillListBoxTemplates()
{
Fill_ListBox($this->ListBox_TEMPLATE, "table_mailer_templates", "ID",
"NAME");
}
protected function UseTemplate()
{
if($this->ListBox_TEMPLATE->Enable)
{
$this->ListBox_TEMPLATE->Enable=false;
$this->Edit_BODY->Value="";
AddToChangedComponents($this->Edit_BODY);
}
else
{
$this->ListBox_TEMPLATE->Enable=true;
if($this->ListBox_TEMPLATE->Value == null)
{
$ds = new ODBDataSet("", $this, GetConnection("MainDBConnection"));
$QueryText = "SELECT ID FROM table_mailer_templates LIMIT 1";
$ds->Open($QueryText);
if($ds->RowCount > 0)
{
$this->ListBox_TEMPLATE->Value = $ds->GetFieldValue("ID");
$this->LoadMailTemplate();
}
}
else
{
$this->LoadMailTemplate();
}
}
AddToChangedComponents($this->ListBox_TEMPLATE);
}
public function LoadMailTemplate()
{
$template=GetRESULT("SELECT BODY AS RESULT FROM
table_mailer_templates
WHERE ID=".$this->ListBox_TEMPLATE->Value);
$this->Edit_BODY->Value=$template;
AddToChangedComponents($this->Edit_BODY);
}
protected function ButtonAddTemplate_OnClick()
{
$save_template=new OFormSaveAsTemplate("OFormSaveAsTemplate",
114
$_SESSION["WorkSpace"]->MainForm, $this->Edit_BODY->Value);
$save_template->SetCenterPosition();
$save_template->ShowModal();
}
protected function ButtonSend_OnClick()
{
$files=array();
$files_list=$this->Files->GetFiles();
$files_cnt=$files_list->Count();
for($i=0; $i<$files_cnt; $i++)
{
$files[]=$files_list->Item($i);
}
$files=implode(",", $files);
$_str=$this->Edit_TO->Value;
$mails=explode(",", $_str);
$cnt=count($mails);
GetConnection("MainDBConnection")->sql_query(
"INSERT INTO table_mailer_history (MAILS, NAME, BODY, FILES,
CNT)
VALUES
('".$this->Edit_TO->Value."', '".$this->Edit_SUBJECT->Value."',
'".$this->Edit_BODY->Value."', '$files', $cnt)");
$history_id=GetConnection("MainDBConnection")->sql_insert_id();
for($i=0; $i<$cnt; $i++)
{
if(strpos($mails[$i], "<")===false)
{
$mails[$i]="<".$mails[$i].">";
}
$mail=new OString($this, trim($mails[$i]));
$address=trim($mail->CutTextBetween("<", ">"));
$mail->Replace("<", "");
$mail->Replace(">", "");
if($this->is_email($address))
{
$name=trim($mail->Text);
$body=$this->SetTags($this->Edit_BODY->Value,
$this->RecipientsForm->CurrentRecipients[$address]);
$subject=$this->SetTags($this->Edit_SUBJECT->Value,
$this->RecipientsForm->CurrentRecipients[$address]);
$this->AddToQueue($address, $subject, $name, $body, $files, $history_id);
}
}
$this->SendGlobalEvent("database_data_changed", "table_mailer_history");
$this->Close();
}
public function AddToQueue($_address, $_subject, $_name, $_body,
115
$_files="", $_history_id=-1)
{
GetConnection("MainDBConnection")->sql_query(
"INSERT INTO table_mailer_queue (EMAIL, SUBJECT, NAME, BODY,
FILES, HISTORY_ID)
VALUES
('$_address', '".$_subject."', '$_name', '".$_body."', '$_files', $_history_id)");
}
/**
* подстановка тэгов в строку
*
* @param string $_body текст
* @param array $_recipients_info массив
$_recipients_info=>array(FIELDNAME=>VALUE)
* @return string текст с подставленными тэгами
*
*/
public function SetTags($_body, $_recipients_info)
{
if($this->UsersTable!="" && $this->MailField!="")
{
$_body=$this->SetTagsFromDB($_body, $_recipients_info);
}
else
{
foreach($_recipients_info as $FieldName=>$val)
{
if(is_string($val))
$_body=str_replace("{".$FieldName."}", $val, $_body);
}
}
return $_body;
}
/**
* подстановка значений из бд
*
* @param string $_body текст
* @param array $_recipients_info значения (адрес и имя)
* @return string текст
*
*/
public function SetTagsFromDB($_body, $_recipients_info)
{
$query="SELECT * FROM ".$this->UsersTable."
WHERE ".$this->MailField."='".$_recipients_info['MAIL']."'";
$ds = new ODBDataSet("", $this, GetConnection("MainDBConnection"));
if($ds->Open($query) && $ds->RowCount>0)
{
116
foreach ($ds->ColumnInfo->Items as $col_info)
{
$FieldName = $col_info->Name;
$FieldValue = $ds->GetFieldValue($FieldName);
$_body=str_replace("{".$FieldName."}", $FieldValue, $_body);
}
}
else
{
$_body=str_replace("{".$this->NameField."}", $_recipients_info['NAME'],
$_body);
$_body=str_replace("{".$this->MailField."}", $_recipients_info['MAIL'],
$_body);
}
return $_body;
}
public function is_email($email){
$p = '/^[a-z0-9!#$%&*+-=?^_`{|}~]+(\.[a-z0-9!#$%&*+-=?^_`{|}~]+)*';
$p.= '@([-a-z0-9]+\.)+([a-z]{2,3}';
$p.= '|info|arpa|aero|coop|name|museum|mobi)$/ix';
return preg_match($p, $email);
}
}
?>
2.2 Форма выбора адресатов
<?php
/*************************************************************
***************
Description: Форма выбора адресатов
Author: Potapenko Vladimir
Created: 23.04.2013
Version: 1.0.0
Changes info:
= 23.04.2013(Potapenko Vladimir):создан
*************************************************************
***************/
class OFormRecipients extends OForm
{
public $UsersTable;
/**
* Поле с именем получателя
*
* @var string
*
*/
public $NameField;
/**
* Поле с адресом получателя
Источник: https://baza.diplomsite.ru/previewfile/2143