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

Внимание! Если размещение файла нарушает Ваши авторские права, то обязательно сообщите нам
107
>CreateFromXML(ProjectPath().'forms/clients/LayoutOFormView_clients.xml');
$this->DataAlias="table_clients";
$this->SubTablesKeyId=0;
$this->Attributes=array();
$this->Record=new ODBObject("", $this, "MainDBConnection");
$this->Record->SelectQueryAlias="Select_table_clients";
$this->Record->UpdateQueryAlias="Update_table_clients";
$this->Record->InsertQueryAlias="Insert_table_clients";
$this->Assigner->Add($this->Edit_NAME, "NAME", $this->Label_NAME,
true);
$this->Assigner->Add($this->Edit_FULLNAME, "FULLNAME", $this-
>Label_FULLNAME, true);
$this->Assigner->Add($this->ListBox_ID_TYPE, "ID_TYPE");
$this->Assigner->Add($this->TextArea_ADDRESS, "ADDRESS");
$this->Assigner->Add($this->Edit_PHONE, "PHONE");
$this->Assigner->Add($this->Edit_EMAIL, "EMAIL");
$this->Assigner->Add($this->Edit_WEBSITE, "WEBSITE");
$this->Assigner->Add($this->TextArea_NOTICE, "NOTICE");
}
protected function AfterAssign()
{
parent::AfterAssign();
if($this->Edit_FULLNAME->Value!="")
{
$this->Title=$this->Edit_FULLNAME->Value;
}
Fill_ListBox($this->ListBox_ID_TYPE, "table_client_types", "ID",
"NAME");
$this->FormClientEmployees->Work($this->GetCurrentRecordId());
$this->FormClientHistory->Work($this->GetCurrentRecordId());
$this->FormClientPlans->Work($this->GetCurrentRecordId());
$this->FormClientProjects->Work($this->GetCurrentRecordId());
$this->FormClientBranchs->Work($this->GetCurrentRecordId());
$this->FormClientHeads->Work($this->GetCurrentRecordId());
if($this->GetCurrentRecordId()<=0)
{
$this->ListBox_ID_TYPE->Value=4;
}
$this->LoadClientAttributes();
}
protected function LoadClientAttributes()
{
$query="SELECT cp.ID, cp.NAME FROM table_client_params cp
LEFT JOIN table_cp_relation cpr ON cpr.ID_PARAM=cp.ID
WHERE cpr.ID_CLIENT='".$this->GetCurrentRecordId()."'";
$ds=new ODBDataSet("", $this, GetConnection("MainDBConnection"));
$ds->Open($query);
for($i=0; $i<$ds->RowCount; $i++)
108
{
$ds->SetRow($i);
$id=$ds->GetFieldValue("ID");
$name=$ds->GetFieldValue("NAME");
$this->Attributes[$id]=$name;
}
$this->SetClientAttributes();
}
protected function GetCurrentRecordId()
{
$result=intval($this->Record->PropertyValue("ID"));
if($result<=0)
{
$result=UserId();
$result=$result-($result*2);
$this->SubTablesKeyId=$result;
}
return $result;
}
protected function AfterOpen()
{
$record_id=$this->GetCurrentRecordId();
if($record_id<=0)
{
$this->AddClientHistoryLine($record_id, "Контрагент создан");
}
else
{
$this->AddMainContactInfo();
}
}
protected function AddMainContactInfo()
{
$query="SELECT NAME, PHONE, EMAIL, POSITION FROM
table_clients_employees WHERE
IS_MAIN_CONTACT='1' AND ID_CLIENT='".$this-
>GetCurrentRecordId()."' LIMIT 1";
$ds=new ODBDataSet("", $this, GetConnection("MainDBConnection"));
$ds->Open($query);
for($i=0; $i<$ds->RowCount; $i++)
{
$this->LabelContactNameValue->Text=$ds->GetFieldValue("NAME");
$this->LabelContactPositionValue->Text=
$ds->GetFieldValue("POSITION")==""?"-":$ds-
>GetFieldValue("POSITION");
$this->LabelContactPhoneValue->Text=
$ds->GetFieldValue("PHONE")==""?"-":$ds->GetFieldValue("PHONE");
$this->LabelContactEmailValue->Text=
109
$ds->GetFieldValue("EMAIL")==""?"-":"<a href='mailto:".
$ds->GetFieldValue("EMAIL")."'>".$ds-
>GetFieldValue("EMAIL")."</a>";
}
}
protected function SetClientAttributes()
{
$this->EditAttributes->Value=implode(", ", $this->Attributes);
}
protected function AddClientHistoryLine($_id_client, $_action)
{
$query="INSERT INTO table_client_history(ID_CLIENT,
ACTION_TYPE, ID_DONE_USER,
ACTION_DATE, ISPLANNED) VALUES('".$_id_client."', '$_action',
'".UserId()."', NOW(), 0)";
GetConnection("MainDBConnection")->sql_query($query);
$this->SendGlobalEvent("database_data_changed", "table_client_history");
}
protected function AfterPost()
{
$this->AddRecentActivity("new_client");
if($this->SubTablesKeyId!=0)
{
$this->UpdateClientEmployeesKeyField();
$this->UpdateClientHistoryKeyField();
$this->SendGlobalEvent("database_data_changed", "table_client_history");
}
$this->SaveClientsAttributes();
}
protected function UpdateClientEmployeesKeyField()
{
$query="UPDATE table_clients_employees SET ID_CLIENT='".$this-
>Record->Id().
"' WHERE ID_CLIENT='".$this->SubTablesKeyId."'";
GetConnection("MainDBConnection")->sql_query($query);
}
protected function UpdateClientHistoryKeyField()
{
$query="UPDATE table_client_history SET ID_CLIENT='".$this->Record-
>Id().
"' WHERE ID_CLIENT='".$this->SubTablesKeyId."'";
GetConnection("MainDBConnection")->sql_query($query);
}
protected function ClearAddedClientEmployees()
{
$query="DELETE FROM table_clients_employees WHERE
ID_CLIENT='".
$this->GetCurrentRecordId()."'";
110
GetConnection("MainDBConnection")->sql_query($query);
}
protected function ClearAddedClientHistory()
{
$query="DELETE FROM table_client_history WHERE ID_CLIENT='".
$this->GetCurrentRecordId()."'";
GetConnection("MainDBConnection")->sql_query($query);
}
protected function SaveClientsAttributes()
{
$this->ClearClientAttributes();
$values="";
foreach(array_keys($this->Attributes) as $id)
{
$item="('$id', '".$this->Record->Id()."')";
$values.= $values==""?$item:", ".$item;
}
if($values!="")
{
$query="INSERT INTO table_cp_relation(ID_PARAM, ID_CLIENT)
VALUES".$values;
GetConnection("MainDBConnection")->sql_query($query);
}
}
protected function ClearClientAttributes()
{
$query="DELETE FROM table_cp_relation WHERE ID_CLIENT='".$this-
>GetCurrentRecordId()."'";
GetConnection("MainDBConnection")->sql_query($query);
}
protected function ButtonSelectAttributes_OnClick($_sender, $_event,
$_event_args=null)
{
$f=new OFormDBCheckBoxSelect("FormDBCheckBoxSelect",
$_SESSION["WorkSpace"]->MainForm);
$f->Title="Атрибуты";
$f->Work("ClientParamsSelected", "table_client_params", "ID", "NAME",
implode(",", array_keys($this->Attributes)));
}
public function ButtonCancel_OnClick($_sender, $_event,
$_event_args=null)
{
if($this->GetCurrentRecordId()<=0)
{
$this->ClearAddedClientEmployees();
$this->ClearAddedClientHistory();
}
parent::ButtonCancel_OnClick($_sender, $_event, $_event_args);
111
}
public function CloseButton_OnClick($_sender, $_event,
$_event_args=null)
{
$this->ButtonCancel_OnClick($_sender, $_event, $_event_args);
}
public function ActionPerform($_event_name, $_event_args)
{
if($_event_name === "ClientEmployeeHistory" || $_event_name ===
"ClientProjectHistory")
{
$this-
>AddClientHistoryLine($_event_args["id_client"],$_event_args["add_text"]);
}
if($_event_name === "ClientParamsSelected")
{
$this->Attributes=$_event_args;
$this->SetClientAttributes();
}
if($_event_name === "CloseClientCard")
{
if($_event_args==$this->GetCurrentRecordId())
{
$this->Close();
}
}
}
}
?>
2. Модуль рассылки писем
2.1 Форма редактирования рассылки
<?php
/*************************************************************
***************
Description: форма редактирования рассылки
Author: Potapenko Vladimir
Created: 22.04.2013
Version: 1.0.0
Changes info:
= 22.04.2013(Potapenko Vladimir): создан
*************************************************************
***************/
class OFormViewMailSender extends OForm
{
/**
* Таблица в БД с пользователями
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;
/**
* Поле с адресом получателя

Смотрите также:

"Автоматизация обработки заявок ООО "Проектно-Строительная Компания"
"Автоматизация процесса аттестации персонала для ООО "Нэт Бай Нэт Холдинг"
"Анализ интернет-активности конкурентов ( на примере конкурентов "Газпром нефть")
"Бухгалтерский учёт и аудит расчётов с подотчётними лицами в организации на примере ООО "ЛОЦ 10""
«Психологическое сопровождение персонала в организации на примере ООО «Крокус»
Cовершенствование деловой оценки персонала в организации (на примере ООО "Даймонд кейтеринг развитие")
IPO - инструмент финансирования деятельности организации. На примере ПАО «Нефтяная компания «Лукойл»
PR как средство продвижения организации (на примере ПАО "Тамбовский завод "Комсомолец им. Н.С. Артемова")
PR-коммуникации в сфере общественного питания (на примере кафе-кондитерской «Cream Cheese»)
SMM как средство повышения эффективности работы учреждений социокультурной сферы (на примере Малого театра)