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

Внимание! Если размещение файла нарушает Ваши авторские права, то обязательно сообщите нам
117
*
* @var string
*
*/
public $MailField;
/**
* Имя поля, куда надо записать адреса
*
* @var string
*
*/
public $ReturnToEdit;
/**
* Выделеные получатели
*
* @var string
*
*/
public $SelectedRecipients;
/**
* массив всех получателей
*
* @var array
*
*/
public $CurrentRecipients;
public $UseFilters=true;
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->SelectedRecipients=array();
$this-
>CreateFromXML(ProjectPath()."forms/mail_sender/LayoutOFormRecipients.xml
");
$this->GenFilters();
$this->FillCheckBox();
}
public function UpdateList()
{
$this->CheckListBox_RECIPIENTS->Clear();
$this->FillCheckBox();
AddToChangedComponents($this->CheckListBox_RECIPIENTS);
}
118
public function ClearFilters()
{
$this->CheckListBox_RECIPIENTS->Clear();
$pre=$this->UseFilters;
$this->UseFilters=false;
$this->FillCheckBox();
$this->UseFilters=$pre;
}
public function Close()
{
$this->Hide();
}
/**
* добавление фильтров
*
*/
protected function GenFilters()
{
$curr_col=0;
$label1=new OLabel("label1", $this->Panel_FILTERS);
$label1->Style->Left=10;
$label1->Style->Top=40;
$label1->Style->FontWeight="bold";
$label1->Style->Width=100;
$label1->Text="Статус";
$ds = new ODBDataSet("", $this, GetConnection("MainDBConnection"));
$query="SELECT * FROM table_client_types";
$cnt=0;
if($ds->Open($query) && $ds->RowCount>0)
{
do
{
$cb=new OCheckBox("filter_cb_".$ds->GetFieldValue("ID"), $this-
>Panel_FILTERS);
$cb->Text=$ds->GetFieldValue("NAME");
$cb->Style->Left=12+150*$curr_col;
$cb->Style->Top=65+25*($cnt);
$cb->Style->Width=150;
$cnt++;
if($cnt>2)
{
$curr_col++;
$cnt=0;
}
}while($ds->NextRow());
}
$curr_col++;
$cnt=0;
119
$label2=new OLabel("label2", $this->Panel_FILTERS);
$label2->Style->Left=10+150*$curr_col;
$label2->Style->Top=40;
$label2->Style->FontWeight="bold";
$label2->Style->Width=100;
$label2->Text="Атрибуты";
$ds = new ODBDataSet("", $this, GetConnection("MainDBConnection"));
$query="SELECT * FROM table_client_params";
if($ds->Open($query) && $ds->RowCount>0)
{
do
{
$cb=new OCheckBox("filter2_cb_".$ds->GetFieldValue("ID"), $this-
>Panel_FILTERS);
$cb->Text=$ds->GetFieldValue("NAME");
$cb->Style->Left=12+150*$curr_col;
$cb->Style->Top=65+25*$cnt;
$cb->Style->Width=110;
$cnt++;
if($cnt>2)
{
$curr_col++;
$cnt=0;
}
}while($ds->NextRow());
}
}
/**
* заполенеие дерева по массиву, который возвращает метод
LoadRecipients
*
* @param array $_array информация о получателе
* @param ONode $_parent родительский узел
*
*/
protected function FillCheckBox($_array=null, $_parent="")
{
if($_array==null)
{
if($this->UsersTable!="" && $this->MailField!="")
$_array=$this->FillCheckBoxByFields();
else
$_array=$this->LoadRecipients();
$this->CurrentRecipients=array();
}
$main_cnt=count($_array);
foreach($_array as $id=>$info)
{
120
$mail=$info['MAIL'];
if($mail=="") $mail=$info['NAME'];
if(!isset($this->CurrentRecipients[$mail]))
{
$this->CurrentRecipients[$mail]=array();
foreach($info as $field=>$val)
{
$this->CurrentRecipients[$mail][$field]=$val;
}
}
$text=$info['NAME'];
if(trim($info['MAIL'])!="") $text.=" <".$info['MAIL'].">";
$current_node = new ONode($text, $this->CheckListBox_RECIPIENTS,
array($id, isset($this->SelectedRecipients[$id])), "");
$this->CheckListBox_RECIPIENTS->AddNode($current_node, $_parent);
if(isset($info['CHILDREN']) && count($info['CHILDREN'])>0)
{
$this->FillCheckBox($info['CHILDREN'], $current_node);
}
}
}
public function RememberCheckbox($_id, $_flag)
{
if($_flag)
$this->SelectedRecipients[$_id]=true;
else
unset($this->SelectedRecipients[$_id]);
}
/**
* Возвращает строкe для запросов
*
* @return mixed фильтр
*/
protected function GenFilterString()
{
$result=array("","");
$keys=$this->Panel_FILTERS->Components->GetKeys();
$attrs=array();
for($i=0; $i<count($keys);$i++)
{
if(strpos(
$this->Panel_FILTERS->Components->Items[$keys[$i]]->Name,
"filter_cb_"
)!==false && $this->Panel_FILTERS->Components->Items[$keys[$i]]-
>Value==1)
{
$info=explode("_", $this->Panel_FILTERS->Components-
>Items[$keys[$i]]->Name);
121
$id=$info[2];
if($result[0]!="") $result[0].=" OR ";
$result[0].=" ID_TYPE=$id";
}
if(strpos(
$this->Panel_FILTERS->Components->Items[$keys[$i]]->Name,
"filter2_cb_"
)!==false && $this->Panel_FILTERS->Components->Items[$keys[$i]]-
>Value==1)
{
$info=explode("_", $this->Panel_FILTERS->Components-
>Items[$keys[$i]]->Name);
$id=$info[2];
$attrs[]=$id;
}
}
if($result[0]!="")$result[0]="(".$result[0].")";
if($this->Panel_FILTERS->Edit_SEARCH->Value!="")
{
$name=$this->Panel_FILTERS->Edit_SEARCH->Value;
if($result[1]!="") $result[1].=" AND ";
$result[1].=" (NAME LIKE '%$name%' OR EMAIL LIKE '%$name%')";
if($result[0]!="") $result[0].=" AND ";
$result[0].=" (NAME LIKE '%$name%' OR FULLNAME LIKE
'%$name%' OR EMAIL LIKE '%$name%')";
}
if(count($attrs)!=0)
{
if($result[0]!="") $result[0].=" AND ";
$result[0].="(ID IN (SELECT ID_CLIENT FROM table_cp_relation
WHERE ID_PARAM IN (".implode(",", $attrs).")))";
}
return $result;
}
/**
* заполнение массива с получателями по значениям, переданным в
конструкторе
*
* @return array Массив получателей
*/
protected function LoadRecipients()
{
if($this->UseFilters)
$filters=$this->GenFilterString();
else
$filters=array("","");
$result=array();
$ds = new ODBDataSet("", $this, GetConnection("MainDBConnection"));
Источник: https://baza.diplomsite.ru/previewfile/2143