<? require_once($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_before.php'); global $DB; $_POST = json_decode(file_get_contents('php://input'), true); if ($_POST == null) { echo "please pass the parameters"; } else { if (!$_POST['ID']) { echo "contact id is not found"; } else { $update_field = ''; $sql = 'SELECT '; $insert = 'UPDATE b_uts_crm_contact SET '; foreach ($_POST['fields'] as $key => $value) { $sql .= $key . ','; $insert .= $key . '= "' . $value . '" ,'; } $sql = rtrim($sql, ','); $insert = rtrim($insert, ','); $data = []; $sql1 = "$sql FROM b_uts_crm_contact WHERE VALUE_ID=" . $_POST['ID']; $sqlnew = $DB->query($sql1); // print_r($sql1); if ($sqlnew->SelectedRowsCount() > 0) { while ($row = $sqlnew->Fetch()) { $data = $row; } } $full_name = ''; $email = ''; $update = "$insert WHERE VALUE_ID=" . $_POST['ID']; $DB->query($update); $nsql = "SELECT FULL_NAME,HAS_EMAIL FROM b_crm_contact WHERE ID=" . $_POST['ID']; $sqln = $DB->query($nsql); // print_r($sql1); if ($sqln->SelectedRowsCount() > 0) { while ($row3 = $sqln->Fetch()) { $full_name = $row3['FULL_NAME']; $email = $row3['HAS_EMAIL']; } } $fname = ''; $update_field = ''; foreach ($_POST['fields'] as $key1 => $value1) { if ($email == "Y") { $sql1 = "SELECT `VALUE` FROM b_crm_dp_comm_mcd WHERE `TYPE` = 'EMAIL' AND `ENTITY_ID`=" . $_POST['ID']; $newsql = $DB->query($sql1); if ($newsql->SelectedRowsCount() > 0) { while ($row2 = $newsql->Fetch()) { $email = $row2['VALUE']; } } } $querynew = "SELECT p.EDIT_FORM_LABEL FROM b_user_field_lang p JOIN b_user_field t ON t.ID =p.USER_FIELD_ID WHERE t.FIELD_NAME='$key1'"; $newsql1 = $DB->query($querynew); if ($newsql1->SelectedRowsCount() > 0) { while ($row3 = $newsql1->Fetch()) { $fname = $row3['EDIT_FORM_LABEL']; } } $sql = "insert into audit_contact (contact_id, field, before_value, after_value, contact_email, contact_name, field_name) values ('" . $_POST['ID'] . "','" . $key1 . "' , '" . $data[$key1] . "' ,'" . $value1 . "','" . $email . "','" . $full_name . "','" . $fname . "')"; $DB->query($sql); $select1 = "SELECT * FROM terminate_business_process WHERE Field = '$key1'"; $sqls = $DB->query($select1); if ($sqls->SelectedRowsCount() > 0) { while ($rows = $sqls->Fetch()) { $bp_id = $rows['BP_ID']; $update_data = $rows['Operator']; $update_data = unserialize($update_data); $opr = $update_data[0]; $newvalue[] = explode("'", $update_data[1])[1]; if ($opr == '!') { if (!in_array($value1, $newvalue)) { $cid = 'CONTACT_' . $_POST['ID']; $select = "SELECT * FROM b_bp_workflow_state WHERE STATE = 'InProgress' AND WORKFLOW_TEMPLATE_ID = '$bp_id' AND DOCUMENT_ID = '$cid'"; $result = $DB->query($select); if ($result->SelectedRowsCount() > 0) { while ($row = $result->Fetch()) { $cid = $row['DOCUMENT_ID']; $wid = $row['ID']; $entity = $row['ENTITY']; $mid = $row['MODULE_ID']; define("NO_KEEP_STATISTIC", true); define("NOT_CHECK_PERMISSIONS", true); require_once($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_before.php'); $arErrorsTmp = array(); if (CModule::IncludeModule("bizproc")) { CBPDocument::TerminateWorkflow( $wid, array("$mid", "$entity", "$cid"), $arErrorsTmp ); } } } } } if ($opr == '=') { if (in_array($value1, $newvalue)) { $cid = 'CONTACT_' . $_POST['ID']; $select = "SELECT * FROM b_bp_workflow_state WHERE STATE = 'InProgress' AND WORKFLOW_TEMPLATE_ID = $bp_id AND DOCUMENT_ID = '$cid'"; $result = $DB->query($select); if ($result->SelectedRowsCount() > 0) { while ($row = $result->Fetch()) { $cid = $row['DOCUMENT_ID']; $wid = $row['ID']; $entity = $row['ENTITY']; $mid = $row['MODULE_ID']; define("NO_KEEP_STATISTIC", true); define("NOT_CHECK_PERMISSIONS", true); require_once($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_before.php'); $arErrorsTmp = array(); if (CModule::IncludeModule("bizproc")) { CBPDocument::TerminateWorkflow( $wid, array("$mid", "$entity", "$cid"), $arErrorsTmp ); } } } } } } } $update_field .= $key1 . '|'; } $update_field = rtrim($update_field, '|'); if (empty($update_field)) { return false; } else { $select = "SELECT bp_id FROM config WHERE field REGEXP '$update_field'"; $result = $DB->query($select); if ($result->SelectedRowsCount() > 0) { while ($row = $result->Fetch()) { $sqlnew = "SELECT `NAME` FROM b_bp_workflow_template WHERE ID=" . $row['bp_id']; $newresult = $DB->query($sqlnew); if ($newresult->SelectedRowsCount() > 0) { while ($newrow = $newresult->Fetch()) { $workflow_name = $newrow['NAME']; } } $insertnew = "INSERT INTO audit_business_process (contact_id, bp_id, workflow_name) VALUES ('" . $_POST['ID'] . "','" . $row['bp_id'] . "','" . $workflow_name . "')"; $DB->query($insertnew); define("NO_KEEP_STATISTIC", true); define("NOT_CHECK_PERMISSIONS", true); $bp = $row['bp_id']; $c_id = $_POST['ID']; require_once($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_before.php'); $arErrorsTmp = array(); if (CModule::IncludeModule("bizproc")) { CBPDocument::StartWorkflow( $bp, array("crm", "CCrmDocumentContact", "CONTACT_".$c_id), [], $arErrorsTmp ); } } } } } }
Write, Run & Share PHP code online using OneCompiler's PHP online compiler for free. It's one of the robust, feature-rich online compilers for PHP language, running on the latest version 7. Getting started with the OneCompiler's PHP compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as PHP
and start coding.
OneCompiler's PHP online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample PHP program which takes name as input and prints hello message with your name.
<?php
fscanf(STDIN, "%s\n", $name);
echo "Hello ".$name.".\n";
?>
PHP(Hypertext Preprocessor) is widely used server sripting language by Rasmus Lerdorf in the year 1994.
In PHP, there is no need to explicitly declare variables to reserve memory space. When you assign a value to a variable, declaration happens automatically. Variables are case-sensitive in PHP.
$variable_name = value;
If, If-else, Nested-Ifs are used when you want to perform a certain set of operations based on conditional expressions.
if(conditional-expression){
//code
}
if(conditional-expression){
//code if condition is true
} else {
//code if condition is false
}
if(condition-expression1) {
//code if above condition is true
} elseif(condition-expression2){
//code if above condition is true
}
elseif(condition-expression3) {
//code if above condition is true
}
...
else {
//code if all the conditions are false
}
Switch is used to execute one set of statement from multiple conditions.
switch(conditional-expression) {
case value1:
// code if the above value is matched
break; // optional
case value2:
// code if the above value is matched
break; // optional
...
default:
// code to be executed when all the above cases are not matched;
}
For loop is used to iterate a set of statements based on a condition.
for(Initialization; Condition; Increment/decrement){
// code
}
// you can use any of the below syntax
foreach ($array as $element-value) {
//code
}
foreach ($array as $key => $element-value) {
//code
}
While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.
while(condition) {
// code
}
Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.
do {
// code
} while (condition);
Function is a sub-routine which contains set of statements. Usually functions are written when multiple calls are required to same set of statements which increases re-usuability and modularity.
function function_name(parameters) {
//code
}
function_name (parameters)