24 $data[
'CONNECTOR'] =
'Bitrix\Form\SenderConnectorForm';
30if (Loader::includeModule(
'sender'))
32 class SenderConnectorForm
extends \Bitrix\Sender\Connector
37 public function getName()
45 public function getCode()
53 public function requireConfigure()
59 public function getData()
61 $formId = $this->getFieldValue(
'FORM',
null);
62 $propertyNameId = $this->getFieldValue(
'PROPERTY_NAME',
null);
63 $propertyEmailId = $this->getFieldValue(
'PROPERTY_EMAIL',
null);
65 $formResultsDb = new \CDBResult();
66 $dataResult = array();
68 if($formId && $propertyEmailId)
71 $formResultDb = \CFormResult::GetList($formId,
"s_timestamp", $order=
"asc", $filter,
null,
"N");
72 while ($formResult = $formResultDb->Fetch())
74 $answerList = \CFormResult::GetDataByID(
82 foreach($answerList as $fieldCode => $fieldsAnswer)
84 if($fieldsAnswer[0][
'TITLE_TYPE'] ==
'text')
86 if($fieldsAnswer[0][
'FIELD_ID'] == $propertyNameId)
87 $data[
'NAME'] = $fieldsAnswer[0][
'USER_TEXT'];
89 if($fieldsAnswer[0][
'FIELD_ID'] == $propertyEmailId)
90 $data[
'EMAIL'] = $fieldsAnswer[0][
'USER_TEXT'];
95 if(!empty($data[
'EMAIL']))
97 if(intval($formResult[
'USER_ID']) > 0)
98 $data[
'USER_ID'] = intval($formResult[
'USER_ID']);
100 $dataResult[] = $data;
105 $formResultsDb->InitFromArray($dataResult);
106 return $formResultsDb;
112 public function getForm()
118 $formDb = \CForm::GetList();
119 while($form = $formDb->Fetch())
121 $formList[] = array(
'ID' => $form[
'ID'],
'NAME' => $form[
'NAME']);
123 if(!empty($formList))
124 $formList = array_merge(
125 array(array(
'ID' =>
'',
'NAME' =>
Loc::getMessage(
'sender_connector_form_select'))),
129 $formList = array_merge(
130 array(array(
'ID' =>
'',
'NAME' =>
Loc::getMessage(
'sender_connector_form_empty'))),
137 $propertyToForm = array();
138 $propertyList = array();
139 $propertyList[
''][] = array(
'ID' =>
'',
'NAME' =>
Loc::getMessage(
'sender_connector_form_select'));
140 $propertyList[
'EMPTY'][] = array(
'ID' =>
'',
'NAME' =>
Loc::getMessage(
'sender_connector_form_prop_empty'));
141 foreach($formList as $form)
143 if(empty($form[
'ID']))
continue;
145 $formFieldsDb = \CFormField::GetList($form[
'ID'],
'N');
146 while ($formFields = $formFieldsDb->Fetch())
148 if($formFields[
'TITLE_TYPE'] !=
'text')
continue;
150 if (!array_key_exists($formFields[
'FORM_ID'], $propertyList))
152 $propertyList[$formFields[
'FORM_ID']][] = array(
159 $propertyList[$formFields[
'FORM_ID']][] = array(
160 'ID' => $formFields[
'ID'],
161 'NAME' => $formFields[
'TITLE']
165 $propertyToForm[$formFields[
'ID']] = $formFields[
'FORM_ID'];
173 $formInput =
'<select name="'.$this->getFieldName(
'FORM').
'" id="'.$this->getFieldId(
'FORM').
'" onChange="FormSelect'.$this->getFieldId(
'FORM').
'()">';
174 foreach($formList as $form)
176 $inputSelected = ($form[
'ID'] == $this->getFieldValue(
'FORM') ?
'selected' :
'');
177 $formInput .=
'<option value="'.$form[
'ID'].
'" '.$inputSelected.
'>';
178 $formInput .= htmlspecialcharsbx($form[
'NAME']);
179 $formInput .=
'</option>';
181 $formInput .=
'</select>';
187 $formPropertyNameInput =
'<select name="'.$this->getFieldName(
'PROPERTY_NAME').
'" id="'.$this->getFieldId(
'PROPERTY_NAME').
'">';
188 if(array_key_exists($this->getFieldValue(
'PROPERTY_NAME', 0), $propertyToForm))
190 $propertyCollcetion = $propertyList[$propertyToForm[$this->getFieldValue(
'PROPERTY_NAME', 0)]];
194 $propertyCollcetion = $propertyList[
''];
196 foreach($propertyCollcetion as $property)
198 $inputSelected = ($property[
'ID'] == $this->getFieldValue(
'PROPERTY_NAME') ?
'selected' :
'');
199 $formPropertyNameInput .=
'<option value="'.$property[
'ID'].
'" '.$inputSelected.
'>';
200 $formPropertyNameInput .= htmlspecialcharsbx($property[
'NAME']);
201 $formPropertyNameInput .=
'</option>';
203 $formPropertyNameInput .=
'</select>';
209 $formPropertyEmailInput =
'<select name="'.$this->getFieldName(
'PROPERTY_EMAIL').
'" id="'.$this->getFieldId(
'PROPERTY_EMAIL').
'">';
210 if(array_key_exists($this->getFieldValue(
'PROPERTY_EMAIL', 0), $propertyToForm))
212 $propertyCollcetion = $propertyList[$propertyToForm[$this->getFieldValue(
'PROPERTY_EMAIL', 0)]];
216 $propertyCollcetion = $propertyList[
''];
218 foreach($propertyCollcetion as $property)
220 $inputSelected = ($property[
'ID'] == $this->getFieldValue(
'PROPERTY_EMAIL') ?
'selected' :
'');
221 $formPropertyEmailInput .=
'<option value="'.$property[
'ID'].
'" '.$inputSelected.
'>';
222 $formPropertyEmailInput .= htmlspecialcharsbx($property[
'NAME']);
223 $formPropertyEmailInput .=
'</option>';
225 $formPropertyEmailInput .=
'</select>';
230 function FormSelect".$this->getFieldId(
'FORM').
"()
232 var iblock = BX('".$this->getFieldId(
'FORM').
"');
233 FormPropertyAdd(iblock, BX('".$this->getFieldId(
'PROPERTY_NAME').
"'));
234 FormPropertyAdd(iblock, BX('".$this->getFieldId(
'PROPERTY_EMAIL').
"'));
236 function FormPropertyAdd(iblock, iblockProperty)
238 if(iblockProperty.length>0)
240 for (var j in iblockProperty.options)
242 iblockProperty.options.remove(j);
246 if(formProperties[iblock.value] && formProperties[iblock.value].length>0)
247 propList = formProperties[iblock.value];
249 propList = formProperties['EMPTY'];
250 for(var i in propList)
252 var optionName = propList[i]['NAME'];
253 var optionValue = propList[i]['ID'];
254 iblockProperty.options.add(new Option(optionName, optionValue));
259 var formProperties = ".\CUtil::PhpToJSObject($propertyList).
";
266 '.Loc::getMessage(
'sender_connector_form_required_settings').
'
271 <td>'.$formInput.
'</td>
275 <td>'.$formPropertyNameInput.
'</td>
279 <td>'.$formPropertyEmailInput.
'</td>
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)