示例#1
0
function TextDump(&$Var, $Level = 0)
{
    if (is_array($Var)) {
        $Type = "Array[" . count($Var) . "]";
    } else {
        if (is_object($Var)) {
            $Type = "Object";
        } else {
            $Type = "";
        }
    }
    if ($Type) {
        echo "{$Type}\n";
        for (Reset($Var), $Level++; list($k, $v) = each($Var);) {
            if (is_array($v) && $k === "GLOBALS") {
                continue;
            }
            for ($i = 0; $i < $Level * 3; $i++) {
                echo " ";
            }
            echo "<b>- [" . htmlspecialchars($k) . "]</b> => ", TextDump($v, $Level);
        }
    } else {
        echo "'" . htmlspecialchars($Var) . "'\n";
    }
}
示例#2
0
/**
* Помощник для отладки
*
* @version 1.0
* @author Ibragimov "MpaK" Renat <*****@*****.**>
 * @copyright Copyright (c) 2009-2010, BESTWEB ltd. www.BESTWEB.ru
*/
function TextDump(&$Var, $Level = 0)
{
    $out = '';
    if (is_array($Var)) {
        $Type = "Array[" . count($Var) . "]";
    } else {
        if (is_object($Var)) {
            $Type = "Object";
        } else {
            $Type = "";
        }
    }
    if ($Type) {
        $out .= "{$Type}\n";
        for (Reset($Var), $Level++; list($k, $v) = each($Var);) {
            if (is_array($v) && $k === "GLOBALS") {
                continue;
            }
            for ($i = 0; $i < $Level * 3; $i++) {
                $out .= " ";
            }
            $out .= "<b>" . HtmlSpecialChars($k) . "</b> => " . TextDump($v, $Level);
        }
    } else {
        $out .= '"' . HtmlSpecialChars($Var) . '"' . "\n";
    }
    return $out;
}
示例#3
0
 function PageLoad(&$form)
 {
     $tv = $this->template_variables;
     $ttv = count($tv);
     for ($t = '', Reset($tv), $v = 0; $v < $ttv; Next($tv), ++$v) {
         $k = Key($tv);
         if ($v > 0) {
             $t .= ',';
         }
         $t .= ' ' . $form->EncodeJavascriptString($k) . ': { preview: ' . $form->EncodeJavascriptString($tv[$k]['Preview']) . ', inline: ' . (isset($tv[$k]['Inline']) && $tv[$k]['Inline'] ? 'true' : 'false') . (isset($tv[$k]['Title']) ? ', title: ' . $form->EncodeJavascriptString($tv[$k]['Title']) : '');
         if (isset($tv[$k]['Alternatives'])) {
             $t .= ', alternatives: {';
             $va = $tv[$k]['Alternatives'];
             $tva = count($va);
             for (Reset($va), $a = 0; $a < $tva; Next($va), ++$a) {
                 $ka = Key($va);
                 if ($a > 0) {
                     $t .= ',';
                 }
                 $t .= ' ' . $form->EncodeJavascriptString($ka) . ': { preview: ' . $form->EncodeJavascriptString($va[$ka]['Preview']) . (isset($va[$ka]['Title']) ? ', title: ' . $form->EncodeJavascriptString($va[$ka]['Title']) : '') . ' }';
             }
             $t .= ' }';
         }
         $t .= ' }';
     }
     $css = $this->external_css;
     $tc = count($css);
     for ($e = '', $c = 0; $c < $tc; ++$c) {
         if ($c > 0) {
             $e .= ',';
         }
         $e .= ' ' . $form->EncodeJavascriptString($css[$c]);
     }
     return 'var e = new ML.HTMLEditor.Editor();' . "\n" . 'e.debug = ' . ($this->debug ? 'true' : 'false') . ';' . (strlen($t) ? ' e.templateVariables = {' . $t . '};' : '') . (strlen($e) ? ' e.externalCSS = [' . $e . '];' : '') . ' e.insertEditor(' . $form->EncodeJavascriptString($this->input) . ', { id: ' . $form->EncodeJavascriptString($this->textarea['ID']) . ', name: ' . $form->EncodeJavascriptString($this->textarea['NAME']) . (isset($this->textarea['VALUE']) ? ', value: ' . $form->EncodeJavascriptString($this->textarea['VALUE']) : '') . (isset($this->textarea['ROWS']) ? ', rows: ' . $form->EncodeJavascriptString($this->textarea['ROWS']) : '') . (isset($this->textarea['COLS']) ? ', cols: ' . $form->EncodeJavascriptString($this->textarea['COLS']) : '') . (isset($this->textarea['STYLE']) ? ', style: ' . $form->EncodeJavascriptString($this->textarea['STYLE']) . (isset($this->textarea['CLASS']) ? ', className: ' . $form->EncodeJavascriptString($this->textarea['CLASS']) : '') : '') . ' });';
 }
 function SendMail($to, $subject, $body, $headers)
 {
     $command = $this->sendmail_path . " -t";
     if (isset($this->delivery["Headers"])) {
         $headers_values = $this->delivery["Headers"];
         for ($return_path = "", $header = 0, Reset($headers_values); $header < count($headers_values); $header++, Next($headers_values)) {
             if (strtolower(Key($headers_values)) == "return-path") {
                 $return_path = $headers_values[Key($headers_values)];
                 break;
             }
         }
         if (strlen($return_path)) {
             $command .= " -f {$return_path}";
         }
     }
     if (strlen($this->sendmail_arguments)) {
         $command .= " " . $this->sendmail_arguments;
     }
     if (!($pipe = popen($command, "w"))) {
         return $this->OutputError("it was not possible to open sendmail input pipe");
     }
     if (!fputs($pipe, "To: {$to}\n") || !fputs($pipe, "Subject: {$subject}\n") || $headers != "" && !fputs($pipe, "{$headers}\n") || !fputs($pipe, "\n{$body}")) {
         return $this->OutputError("it was not possible to write sendmail input pipe");
     }
     pclose($pipe);
     return "";
 }
示例#5
0
function textDump(&$var, $level = 0)
{
    if (is_array($var)) {
        $type = "Array[" . count($var) . "]";
    } else {
        if (is_object($var)) {
            $type = "Object";
        } else {
            $type = "";
        }
    }
    if ($type) {
        $rez = "{$type}\n";
        for (Reset($var), $level++; list($k, $v) = each($var);) {
            if (is_array($v) && $k === "GLOBALS") {
                continue;
            }
            for ($i = 0; $i < $level * 3; $i++) {
                $rez .= " ";
            }
            $rez .= $k . ' => ' . textDump($v, $level);
        }
    } else {
        if (is_bool($var)) {
            $rez = ($var ? 'true' : 'false') . "\n";
        } else {
            if (is_long($var) || is_float($var) || intval($var) != 0) {
                $rez = $var . "\n";
            } else {
                $rez = '"' . $var . '"' . "\n";
            }
        }
    }
    return $rez;
}
示例#6
0
文件: dumpvar.php 项目: naffbeats/cms
/**
 * @author Melvil (https://github.com/Melvil)
 **/
function dumpVar(&$Var, $Level = 0, $Var_s = null, $level_limit = 5)
{
	$is_ob_ar = false;
	$Type = gettype($Var);
	if (is_array($Var))
	{
		$is_ob_ar = true;
		$Type = 'Array[' . count($Var) . ']';
	}
	if (is_object($Var)) $is_ob_ar = true;
	if ($Level == 0)
	{
		if ($Var_s) echo NL . '<br>' . NL . '<b><span style="color:#ff0000">' . $Var_s . ' = {</span></b>';
		if ($is_ob_ar && count($Var)) echo '<pre>' . NL;
		else echo NL . '<tt>';
		$Level_zero = 0;
	}
	if ($is_ob_ar)
	{
		
		if ($Type == 'object') echo '<span style="color:#05a209">object of</span> <span style="color:#A03000">' . get_class($Var) . '</span>';
		else echo '<span style="color:#05a209">' . $Type . '</span>';
		if ($Level > $level_limit)
		{
			if ($level_limit > 1) echo '<b>...</b> LEVEL > 5<br>' . NL;
			else echo NL;
			return;
		}
		echo NL;
		if ($Level == 0 || !is_object($Var))
			for (Reset($Var), $Level++; list($k, $v)=each($Var);)
			{
				for ($i = 0; $i < $Level*3; $i++) echo ' ';
				echo '<b>'.HtmlSpecialChars($k).'</b> => ';
				// if (is_object($v) || ($k === 'GLOBALS' && is_array($v))) { echo "\n"; continue; }
				if ($k === 'GLOBALS' && is_array($v)) { echo NL; continue; }
				dumpVar($v, $Level, null, $level_limit);
			}
	}
	else
	{
		$iss = is_string($Var);
		if ($iss && strlen($Var)>400)
			echo '('.$Type.') <span style="color:#35BBFA">strlen = '.strlen($Var).'</span>' . NL;
		else {
			echo '(' . $Type . ') ' . ($iss ? '"' : '') . '<span style="color:#0000FF">';
			if ($Type == 'boolean') echo ($Var ? 'true' : 'false');
			else echo HtmlSpecialChars($Var);
			echo '</span>' . ($iss ? '"' : '') . NL;
		}
	}
	if (isset($Level_zero))
	{
		if ($is_ob_ar && count($Var)) echo '</pre>'; else echo '</tt>';
		if ($Var_s) echo '<b><span style="color:#ff0000">}</span></b><br>' . NL;
	}
	return true;
}
示例#7
0
 static function loadGlossaryType()
 {
     $type = Options::Get('glossary_type');
     $arr_types = self::getGlossaryTypes();
     if (isset($arr_types[$type])) {
         self::$type = $arr_types[$type];
     } else {
         self::$type = Reset($arr_types);
     }
 }
示例#8
0
 function CheckRequirements()
 {
     Reset($this->requirements);
     $end = GetType($function = Key($this->requirements)) != "string";
     for (; !$end;) {
         if (!function_exists($function)) {
             return $this->requirements[$function];
         }
         Next($this->requirements);
         $end = GetType($function = Key($this->requirements)) != "string";
     }
     return "";
 }
示例#9
0
function DumpArray(&$array, $indent)
{
    for (Reset($array), $node = 0; $node < count($array); Next($array), $node++) {
        echo $indent . "\"" . Key($array) . "\"=";
        $value = $array[Key($array)];
        if (GetType($value) == "array") {
            echo "\n" . $indent . "[\n";
            DumpArray($value, $indent . "\t");
            echo $indent . "]\n";
        } else {
            echo "\"{$value}\"\n";
        }
    }
}
示例#10
0
 function SearchCompleteValues(&$form, $text, &$found)
 {
     if (strlen($text) == 0) {
         $found = $this->complete_values;
     } else {
         $t = strtolower($text);
         for ($found = array(), Reset($this->complete_values), $v = 0; $v < count($this->complete_values); $v++, Next($this->complete_values)) {
             $c = Key($this->complete_values);
             if (!strcmp($t, strtolower(substr($c, 0, strlen($t))))) {
                 $found[$c] = $this->complete_values[$c];
             }
         }
     }
     return '';
 }
function test_quoting(&$message, $test_values, $cs, $quote, $email_header, &$tests, &$failed)
{
    Reset($test_values);
    $end = GetType($value = Key($test_values)) != "string";
    for (; !$end; $tests++) {
        echo "Test value \"", $value, "\"...";
        flush();
        $encoded = $quote ? $message->QuoteText($value) : $message->QuotedPrintableEncode($value, $cs, 1, $email_header);
        if (strcmp($encoded, $test_values[$value])) {
            echo "\tFAIL: returned \"", $encoded, "\" and not \"", $test_values[$value], "\" as expected!\n";
            $failed++;
        } else {
            echo "\tOK!\n";
        }
        Next($test_values);
        $end = GetType($value = Key($test_values)) != "string";
    }
}
示例#12
0
 function AlterTable(&$db, $name, &$changes, $check)
 {
     if ($check) {
         for ($change = 0, Reset($changes); $change < count($changes); Next($changes), $change++) {
             switch (Key($changes)) {
                 case "AddedFields":
                     break;
                 case "RemovedFields":
                     return $db->SetError("Alter table", "database server does not support dropping table columns");
                 case "name":
                 case "RenamedFields":
                 case "ChangedFields":
                 default:
                     return $db->SetError("Alter table", "change type \"" . Key($changes) . "\" not yet supported");
             }
         }
         return 1;
     } else {
         if (isset($changes[$change = "name"]) || isset($changes[$change = "RenamedFields"]) || isset($changes[$change = "ChangedFields"])) {
             return $db->SetError("Alter table", "change type \"{$change}\" not yet supported");
         }
         $query = "";
         if (isset($changes["AddedFields"])) {
             $fields = $changes["AddedFields"];
             for ($field = 0, Reset($fields); $field < count($fields); Next($fields), $field++) {
                 if (!$db->Query("ALTER TABLE {$name} ADD " . $fields[Key($fields)]["Declaration"])) {
                     return 0;
                 }
             }
         }
         if (isset($changes["RemovedFields"])) {
             $fields = $changes["RemovedFields"];
             for ($field = 0, Reset($fields); $field < count($fields); Next($fields), $field++) {
                 if (!$db->Query("ALTER TABLE {$name} DROP " . Key($fields))) {
                     return 0;
                 }
             }
         }
         return 1;
     }
 }
示例#13
0
文件: dumper.php 项目: ashikov/book
function dumperGet(&$obj, $leftSp = "")
{
    if (is_array($obj)) {
        $type = "Array[" . count($obj) . "]";
    } elseif (is_object($obj)) {
        $type = "Object";
    } elseif (gettype($obj) == "boolean") {
        return $obj ? "true" : "false";
    } else {
        return "\"{$obj}\"";
    }
    $buf = $type;
    $leftSp .= "    ";
    for (Reset($obj); list($k, $v) = each($obj);) {
        if ($k === "GLOBALS") {
            continue;
        }
        $buf .= "\n{$leftSp}{$k} => " . dumperGet($v, $leftSp);
    }
    return $buf;
}
示例#14
0
 function CheckRequirements()
 {
     if (isset($this->requirements["imagegif"]) && strcmp($this->image_format, "gif")) {
         $this->requirements["image" . $this->image_format] = "the GD extension is not able to save in the " . strtoupper($this->image_format) . " format";
         unset($this->requirements["imagegif"]);
     }
     if (isset($this->requirements["imagecreatefromgif"]) && strcmp($this->noise_image_format, "gif")) {
         if (strlen($this->noise_image_format)) {
             $this->requirements["imagecreatefrom" . $this->noise_image_format] = "the GD extension is not able to read image files in the " . strtoupper($this->noise_image_format) . " format";
         }
         unset($this->requirements["imagecreatefromgif"]);
     }
     Reset($this->requirements);
     $end = GetType($function = Key($this->requirements)) != "string";
     for (; !$end;) {
         if (!function_exists($function)) {
             return $this->requirements[$function];
         }
         Next($this->requirements);
         $end = GetType($function = Key($this->requirements)) != "string";
     }
     return "";
 }
示例#15
0
 function AlterTable(&$db, $name, &$changes, $check)
 {
     if ($check) {
         for ($change = 0, Reset($changes); $change < count($changes); Next($changes), $change++) {
             switch (Key($changes)) {
                 case "AddedFields":
                     break;
                 case "RemovedFields":
                 case "name":
                 case "RenamedFields":
                 case "ChangedFields":
                 default:
                     return $db->SetError("Alter table", "change type \"" . Key($changes) . "\" not yet supported");
             }
         }
         return 1;
     } else {
         if (isset($changes[$change = "RemovedFields"]) || isset($changes[$change = "name"]) || isset($changes[$change = "RenamedFields"]) || isset($changes[$change = "ChangedFields"])) {
             return $db->SetError("Alter table", "change type \"{$change}\" is not supported by the server");
         }
         $query = "";
         if (isset($changes["AddedFields"])) {
             if (strcmp($query, "")) {
                 $query .= ", ";
             }
             $query .= "ADD ";
             $fields = $changes["AddedFields"];
             for ($field = 0, Reset($fields); $field < count($fields); Next($fields), $field++) {
                 if (strcmp($query, "")) {
                     $query .= ", ";
                 }
                 $query .= $fields[Key($fields)]["Declaration"];
             }
         }
         return strcmp($query, "") ? $db->Query("ALTER TABLE {$name} {$query}") : 1;
     }
 }
示例#16
0
 function ValidateEmailHost($email, $hosts = 0)
 {
     if (!$this->ValidateEmailAddress($email)) {
         return 0;
     }
     $user = strtok($email, "@");
     $domain = strtok("");
     if (GetMXRR($domain, &$hosts, &$weights)) {
         $mxhosts = array();
         for ($host = 0; $host < count($hosts); $host++) {
             $mxhosts[$weights[$host]] = $hosts[$host];
         }
         KSort($mxhosts);
         for (Reset($mxhosts), $host = 0; $host < count($mxhosts); Next($mxhosts), $host++) {
             $hosts[$host] = $mxhosts[Key($mxhosts)];
         }
     } else {
         $hosts = array();
         if (strcmp(@gethostbyname($domain), $domain) != 0) {
             $hosts[] = $domain;
         }
     }
     return count($hosts) != 0;
 }
示例#17
0
 function ExecuteQuery($prepared_query)
 {
     if (!$this->ValidatePreparedQuery($prepared_query)) {
         return 0;
     }
     $index = $prepared_query - 1;
     for ($this->clobs[$prepared_query] = $this->blobs[$prepared_query] = array(), $success = 1, $query = "", $last_position = $position = 0; $position < count($this->prepared_queries[$index]["Positions"]); $position++) {
         if (!isset($this->prepared_queries[$index]["Values"][$position])) {
             return $this->SetError("Execute query", "it was not defined query argument " . ($position + 1));
         }
         $current_position = $this->prepared_queries[$index]["Positions"][$position];
         $query .= substr($this->prepared_queries[$index]["Query"], $last_position, $current_position - $last_position);
         $value = $this->prepared_queries[$index]["Values"][$position];
         if ($this->prepared_queries[$index]["IsNULL"][$position]) {
             $query .= $value;
         } else {
             switch ($this->prepared_queries[$index]["Types"][$position]) {
                 case "clob":
                     if (!($success = $this->GetCLOBFieldValue($prepared_query, $position + 1, $value, $this->clobs[$prepared_query][$position + 1]))) {
                         unset($this->clobs[$prepared_query][$position + 1]);
                         break;
                     }
                     $query .= $this->clobs[$prepared_query][$position + 1];
                     break;
                 case "blob":
                     if (!($success = $this->GetBLOBFieldValue($prepared_query, $position + 1, $value, $this->blobs[$prepared_query][$position + 1]))) {
                         unset($this->blobs[$prepared_query][$position + 1]);
                         break;
                     }
                     $query .= $this->blobs[$prepared_query][$position + 1];
                     break;
                 default:
                     $query .= $value;
                     break;
             }
         }
         $last_position = $current_position + 1;
     }
     if ($success) {
         $query .= substr($this->prepared_queries[$index]["Query"], $last_position);
         if ($this->selected_row_limit > 0) {
             $this->prepared_queries[$index]["First"] = $this->first_selected_row;
             $this->prepared_queries[$index]["Limit"] = $this->selected_row_limit;
         }
         if (isset($this->prepared_queries[$index]["Limit"]) && $this->prepared_queries[$index]["Limit"] > 0) {
             $this->first_selected_row = $this->prepared_queries[$index]["First"];
             $this->selected_row_limit = $this->prepared_queries[$index]["Limit"];
         } else {
             $this->first_selected_row = $this->selected_row_limit = 0;
         }
         $success = $this->ExecutePreparedQuery($prepared_query, $query);
     }
     for (Reset($this->clobs[$prepared_query]), $clob = 0; $clob < count($this->clobs[$prepared_query]); $clob++, Next($this->clobs[$prepared_query])) {
         $this->FreeCLOBValue($prepared_query, Key($this->clobs[$prepared_query]), $this->clobs[$prepared_query][Key($this->clobs[$prepared_query])], $success);
     }
     unset($this->clobs[$prepared_query]);
     for (Reset($this->blobs[$prepared_query]), $blob = 0; $blob < count($this->blobs[$prepared_query]); $blob++, Next($this->blobs[$prepared_query])) {
         $this->FreeBLOBValue($prepared_query, Key($this->blobs[$prepared_query]), $this->blobs[$prepared_query][Key($this->blobs[$prepared_query])], $success);
     }
     unset($this->blobs[$prepared_query]);
     return $success;
 }
示例#18
0
 function Connect($domain = "")
 {
     if (strcmp($this->state, "Disconnected")) {
         $this->error = "connection is already established";
         return 0;
     }
     $this->disconnected_error = 0;
     $this->error = $error = "";
     $this->esmtp_host = "";
     $this->esmtp_extensions = array();
     $hosts = array();
     if ($this->direct_delivery) {
         if (strlen($domain) == 0) {
             return 1;
         }
         $hosts = $weights = $mxhosts = array();
         $getmxrr = $this->getmxrr;
         if (function_exists($getmxrr) && $getmxrr($domain, $hosts, $weights)) {
             for ($host = 0; $host < count($hosts); $host++) {
                 $mxhosts[$weights[$host]] = $hosts[$host];
             }
             KSort($mxhosts);
             for (Reset($mxhosts), $host = 0; $host < count($mxhosts); Next($mxhosts), $host++) {
                 $hosts[$host] = $mxhosts[Key($mxhosts)];
             }
         } else {
             if (strcmp(@gethostbyname($domain), $domain) != 0) {
                 $hosts[] = $domain;
             }
         }
     } else {
         if (strlen($this->host_name)) {
             $hosts[] = $this->host_name;
         }
         if (strlen($this->pop3_auth_host)) {
             $user = $this->user;
             if (strlen($user) == 0) {
                 $this->error = "it was not specified the POP3 authentication user";
                 return 0;
             }
             $password = $this->password;
             if (strlen($password) == 0) {
                 $this->error = "it was not specified the POP3 authentication password";
                 return 0;
             }
             $domain = $this->pop3_auth_host;
             $this->error = $this->ConnectToHost($domain, $this->pop3_auth_port, "Resolving POP3 authentication host \"" . $domain . "\"...");
             if (strlen($this->error)) {
                 return 0;
             }
             if (strlen($response = $this->GetLine()) == 0) {
                 return 0;
             }
             if (strcmp($this->Tokenize($response, " "), "+OK")) {
                 $this->error = "POP3 authentication server greeting was not found";
                 return 0;
             }
             if (!$this->PutLine("USER " . $this->user) || strlen($response = $this->GetLine()) == 0) {
                 return 0;
             }
             if (strcmp($this->Tokenize($response, " "), "+OK")) {
                 $this->error = "POP3 authentication user was not accepted: " . $this->Tokenize("\r\n");
                 return 0;
             }
             if (!$this->PutLine("PASS " . $password) || strlen($response = $this->GetLine()) == 0) {
                 return 0;
             }
             if (strcmp($this->Tokenize($response, " "), "+OK")) {
                 $this->error = "POP3 authentication password was not accepted: " . $this->Tokenize("\r\n");
                 return 0;
             }
             fclose($this->connection);
             $this->connection = 0;
         }
     }
     if (count($hosts) == 0) {
         $this->error = "could not determine the SMTP to connect";
         return 0;
     }
     for ($host = 0, $error = "not connected"; strlen($error) && $host < count($hosts); $host++) {
         $domain = $hosts[$host];
         $error = $this->ConnectToHost($domain, $this->host_port, "Resolving SMTP server domain \"{$domain}\"...");
     }
     if (strlen($error)) {
         $this->error = $error;
         return 0;
     }
     $timeout = $this->data_timeout ? $this->data_timeout : $this->timeout;
     if ($timeout && function_exists("socket_set_timeout")) {
         socket_set_timeout($this->connection, $timeout, 0);
     }
     if ($this->debug) {
         $this->OutputDebug("Connected to SMTP server \"" . $domain . "\".");
     }
     if (!strcmp($localhost = $this->localhost, "") && !strcmp($localhost = getenv("SERVER_NAME"), "") && !strcmp($localhost = getenv("HOST"), "")) {
         $localhost = "localhost";
     }
     $success = 0;
     if ($this->VerifyResultLines("220", $responses) > 0) {
         $success = $this->StartSMTP($localhost);
         if ($this->start_tls) {
             if (!isset($this->esmtp_extensions["STARTTLS"])) {
                 $this->error = "server does not support starting TLS";
                 $success = 0;
             } elseif (!function_exists('stream_socket_enable_crypto')) {
                 $this->error = "this PHP installation or version does not support starting TLS";
                 $success = 0;
             } elseif ($success = $this->PutLine('STARTTLS') && $this->VerifyResultLines('220', $responses) > 0) {
                 $this->OutputDebug('Starting TLS cryptograpic protocol');
                 if (!($success = stream_socket_enable_crypto($this->connection, 1, STREAM_CRYPTO_METHOD_TLS_CLIENT))) {
                     $this->error = 'could not start TLS connection encryption protocol';
                 } else {
                     $this->OutputDebug('TLS started');
                     $success = $this->StartSMTP($localhost);
                 }
             }
         }
         if ($success && strlen($this->user) && strlen($this->pop3_auth_host) == 0) {
             if (!isset($this->esmtp_extensions["AUTH"])) {
                 $this->error = "server does not require authentication";
                 if (isset($this->esmtp_extensions["STARTTLS"])) {
                     $this->error .= ', it probably requires starting TLS';
                 }
                 $success = 0;
             } else {
                 if (strlen($this->authentication_mechanism)) {
                     $mechanisms = array($this->authentication_mechanism);
                 } else {
                     $mechanisms = array();
                     for ($authentication = $this->Tokenize($this->esmtp_extensions["AUTH"], " "); strlen($authentication); $authentication = $this->Tokenize(" ")) {
                         $mechanisms[] = $authentication;
                     }
                 }
                 $credentials = array("user" => $this->user, "password" => $this->password);
                 if (strlen($this->realm)) {
                     $credentials["realm"] = $this->realm;
                 }
                 if (strlen($this->workstation)) {
                     $credentials["workstation"] = $this->workstation;
                 }
                 $success = $this->SASLAuthenticate($mechanisms, $credentials, $authenticated, $mechanism);
                 if (!$success && !strcmp($mechanism, "PLAIN")) {
                     /*
                      * Author:  Russell Robinson, 25 May 2003, http://www.tectite.com/
                      * Purpose: Try various AUTH PLAIN authentication methods.
                      */
                     $mechanisms = array("PLAIN");
                     $credentials = array("user" => $this->user, "password" => $this->password);
                     if (strlen($this->realm)) {
                         /*
                          * According to: http://www.sendmail.org/~ca/email/authrealms.html#authpwcheck_method
                          * some sendmails won't accept the realm, so try again without it
                          */
                         $success = $this->SASLAuthenticate($mechanisms, $credentials, $authenticated, $mechanism);
                     }
                     if (!$success) {
                         /*
                          * It was seen an EXIM configuration like this:
                          * user^password^unused
                          */
                         $credentials["mode"] = SASL_PLAIN_EXIM_DOCUMENTATION_MODE;
                         $success = $this->SASLAuthenticate($mechanisms, $credentials, $authenticated, $mechanism);
                     }
                     if (!$success) {
                         /*
                          * ... though: http://exim.work.de/exim-html-3.20/doc/html/spec_36.html
                          * specifies: ^user^password
                          */
                         $credentials["mode"] = SASL_PLAIN_EXIM_MODE;
                         $success = $this->SASLAuthenticate($mechanisms, $credentials, $authenticated, $mechanism);
                     }
                 }
                 if ($success && strlen($mechanism) == 0) {
                     $this->error = "it is not supported any of the authentication mechanisms required by the server";
                     $success = 0;
                 }
             }
         }
     }
     if ($success) {
         $this->state = "Connected";
         $this->connected_domain = $domain;
     } else {
         fclose($this->connection);
         $this->connection = 0;
     }
     return $success;
 }
示例#19
0
 function Analyze($message, &$results)
 {
     $results = array();
     if (!isset($message['Headers']['content-type:'])) {
         $content_type = 'text/plain';
     } elseif (count($message['Headers']['content-type:']) == 1) {
         $content_type = $message['Headers']['content-type:'];
     } else {
         if (!$this->SetPositionedWarning('message contains multiple content-type headers', 0)) {
             return 0;
         }
         $content_type = $message['Headers']['content-type:'][0];
     }
     $disposition = $this->ParseParameters($content_type, $content_type, $parameters, 'disposition');
     $type = $this->Tokenize($content_type, '/');
     $sub_type = $this->Tokenize(';');
     $copy_body = 1;
     $tolerate_unrecognized = 1;
     switch ($type) {
         case 'multipart':
             $tolerate_unrecognized = 0;
             $copy_body = 0;
             $lp = count($message['Parts']);
             if ($lp == 0) {
                 return $this->SetError($this->decode_bodies ? 'No parts were found in the ' . $content_type . ' part message' : 'It is not possible to analyze multipart messages without parsing the contained message parts. Please set the decode_bodies variable to 1 before parsing the message');
             }
             $parts = array();
             for ($p = 0; $p < $lp; ++$p) {
                 if (!$this->Analyze($message['Parts'][$p], $parts[$p])) {
                     return 0;
                 }
             }
             switch ($sub_type) {
                 case 'alternative':
                     $p = $lp;
                     $results = $parts[--$p];
                     for (--$p; $p >= 0; --$p) {
                         $results['Alternative'][] = $parts[$p];
                     }
                     break;
                 case 'related':
                     $results = $parts[0];
                     for ($p = 1; $p < $lp; ++$p) {
                         $results['Related'][] = $parts[$p];
                     }
                     break;
                 case 'mixed':
                     $results = $parts[0];
                     for ($p = 1; $p < $lp; ++$p) {
                         $results['Attachments'][] = $parts[$p];
                     }
                     break;
                 case 'report':
                     if (isset($parameters['report-type'])) {
                         switch ($parameters['report-type']) {
                             case 'delivery-status':
                                 for ($p = 1; $p < $lp; ++$p) {
                                     if (!strcmp($parts[$p]['Type'], $parameters['report-type'])) {
                                         $results = $parts[$p];
                                         break;
                                     }
                                 }
                                 if (!$this->ReadMessageBody($parts[0], $body, 'Data')) {
                                     return 0;
                                 }
                                 if (strlen($body)) {
                                     $results['Response'] = $body;
                                 }
                                 break;
                         }
                     }
                     $results['Type'] = $parameters['report-type'];
                     break;
                 case 'signed':
                     if ($lp != 2) {
                         return $this->SetError('this ' . $content_type . ' message does not have just 2 parts');
                     }
                     if (strcmp($parts[1]['Type'], 'signature')) {
                         $this->SetErrorWithContact('this ' . $content_type . ' message does not contain a signature');
                         $this->error = '';
                     }
                     $results = $parts[0];
                     $results['Signature'] = $parts[1];
                     break;
             }
             break;
         case 'text':
             switch ($sub_type) {
                 case 'plain':
                     $results['Type'] = 'text';
                     $results['Description'] = 'Text message';
                     break;
                 case 'html':
                     $results['Type'] = 'html';
                     $results['Description'] = 'HTML message';
                     break;
                 default:
                     $results['Type'] = $type;
                     $results['SubType'] = $sub_type;
                     $results['Description'] = 'Text file in the ' . strtoupper($sub_type) . ' format';
                     break;
             }
             break;
         case 'video':
             $results['Type'] = $type;
             $results['SubType'] = $sub_type;
             $results['Description'] = 'Video file in the ' . strtoupper($sub_type) . ' format';
             break;
         case 'image':
             $results['Type'] = $type;
             $results['SubType'] = $sub_type;
             $results['Description'] = 'Image file in the ' . strtoupper($sub_type) . ' format';
             break;
         case 'audio':
             $results['Type'] = $type;
             $results['SubType'] = $sub_type;
             $results['Description'] = 'Audio file in the ' . strtoupper($sub_type) . ' format';
             break;
         case 'application':
             switch ($sub_type) {
                 case 'octet-stream':
                 case 'x-msdownload':
                     $results['Type'] = 'binary';
                     $results['Description'] = 'Binary file';
                     break;
                 case 'pdf':
                     $results['Type'] = $sub_type;
                     $results['Description'] = 'Document in PDF format';
                     break;
                 case 'postscript':
                     $results['Type'] = $sub_type;
                     $results['Description'] = 'Document in Postscript format';
                     break;
                 case 'msword':
                     $results['Type'] = 'ms-word';
                     $results['Description'] = 'Word processing document in Microsoft Word format';
                     break;
                 case 'vnd.ms-powerpoint':
                     $results['Type'] = 'ms-powerpoint';
                     $results['Description'] = 'Presentation in Microsoft PowerPoint format';
                     break;
                 case 'vnd.ms-excel':
                     $results['Type'] = 'ms-excel';
                     $results['Description'] = 'Spreadsheet in Microsoft Excel format';
                     break;
                 case 'zip':
                 case 'x-zip':
                 case 'x-zip-compressed':
                     $results['Type'] = 'zip';
                     $results['Description'] = 'ZIP archive with compressed files';
                     break;
                 case 'ms-tnef':
                     $results['Type'] = $sub_type;
                     $results['Description'] = 'Microsoft Exchange data usually sent by Microsoft Outlook';
                     break;
                 case 'pgp-signature':
                     $results['Type'] = 'signature';
                     $results['SubType'] = $sub_type;
                     $results['Description'] = 'Message signature for PGP';
                     break;
                 case 'x-pkcs7-signature':
                 case 'pkcs7-signature':
                     $results['Type'] = 'signature';
                     $results['SubType'] = $sub_type;
                     $results['Description'] = 'PKCS message signature';
                     break;
                 case 'vnd.oasis.opendocument.text':
                     $results['Type'] = 'odf-writer';
                     $results['Description'] = 'Word processing document in ODF text format used by OpenOffice Writer';
                     break;
             }
             break;
         case 'message':
             $tolerate_unrecognized = 0;
             switch ($sub_type) {
                 case 'delivery-status':
                     $results['Type'] = $sub_type;
                     $results['Description'] = 'Notification of the status of delivery of a message';
                     if (!$this->ReadMessageBody($message, $body, 'Body')) {
                         return 0;
                     }
                     if ($l = strlen($body)) {
                         $position = 0;
                         $this->ParseHeaderString($body, $position, $headers);
                         $recipients = array();
                         for (; $position < $l;) {
                             $this->ParseHeaderString($body, $position, $headers);
                             if (count($headers)) {
                                 $r = count($recipients);
                                 if (isset($headers['action'])) {
                                     $recipients[$r]['Action'] = $headers['action'];
                                 }
                                 if (isset($headers['status'])) {
                                     $recipients[$r]['Status'] = $headers['status'];
                                 }
                                 if (isset($headers['original-recipient'])) {
                                     strtok($headers['original-recipient'], ';');
                                     $recipients[$r]['Address'] = trim(strtok(''));
                                 } elseif (isset($headers['final-recipient'])) {
                                     strtok($headers['final-recipient'], ';');
                                     $recipients[$r]['Address'] = trim(strtok(''));
                                 }
                             }
                         }
                         $results['Recipients'] = $recipients;
                     }
                     $copy_body = 0;
                     break;
                 case 'rfc822':
                     $results['Type'] = 'message';
                     $results['Description'] = 'E-mail message';
                     break;
             }
             break;
         default:
             $tolerate_unrecognized = 0;
             break;
     }
     if (!isset($results['Type'])) {
         $this->SetErrorWithContact($content_type . ' message parts are not yet recognized');
         $results['Type'] = $this->error;
         $this->error = '';
     }
     if (isset($parameters['charset'])) {
         $results['Encoding'] = strtolower($parameters['charset']);
     }
     if (isset($message['Headers']['subject:'])) {
         if (isset($message['DecodedHeaders']['subject:']) && count($message['DecodedHeaders']['subject:']) == 1 && count($message['DecodedHeaders']['subject:'][0]) == 1) {
             $results['Subject'] = $message['DecodedHeaders']['subject:'][0][0]['Value'];
             $results['SubjectEncoding'] = strtolower($message['DecodedHeaders']['subject:'][0][0]['Encoding']);
         } else {
             $results['Subject'] = $message['Headers']['subject:'];
         }
     }
     if (isset($message['Headers']['date:'])) {
         if (isset($message['DecodedHeaders']['date:']) && count($message['DecodedHeaders']['date:']) == 1 && count($message['DecodedHeaders']['date:'][0]) == 1) {
             $results['Date'] = $message['DecodedHeaders']['date:'][0][0]['Value'];
         } else {
             $results['Date'] = $message['Headers']['date:'];
         }
     }
     $l = count($this->address_headers);
     for (Reset($this->address_headers), $h = 0; $h < $l; Next($this->address_headers), ++$h) {
         $this->CopyAddresses($message, $results, Key($this->address_headers));
     }
     if ($copy_body) {
         if (isset($message['Body'])) {
             $results['Data'] = $message['Body'];
         } elseif (isset($message['BodyFile'])) {
             $results['DataFile'] = $message['BodyFile'];
         } elseif (isset($message['BodyLength'])) {
             $results['DataLength'] = $message['BodyLength'];
         }
         if (isset($message['FileName'])) {
             $results['FileName'] = $message['FileName'];
         }
         if (isset($message['FileDisposition'])) {
             $results['FileDisposition'] = $message['FileDisposition'];
         }
         if (isset($message['Headers']['content-id:'])) {
             $content_id = trim($message['Headers']['content-id:']);
             $l = strlen($content_id);
             if (!strcmp($content_id[0], '<') && !strcmp($content_id[$l - 1], '>')) {
                 $results['ContentID'] = substr($content_id, 1, $l - 2);
             }
         }
     }
     return 1;
 }
示例#20
0
 function DumpDatabaseChanges(&$changes)
 {
     if (isset($changes["TABLES"])) {
         for ($change = 0, Reset($changes["TABLES"]); $change < count($changes["TABLES"]); Next($changes["TABLES"]), $change++) {
             $table_name = Key($changes["TABLES"]);
             MetabaseDebug($this->database, "{$table_name}:");
             if (isset($changes["tables"][$table_name]["Add"])) {
                 MetabaseDebug($this->database, "\tAdded table '{$table_name}'");
             } else {
                 if (isset($changes["TABLES"][$table_name]["Remove"])) {
                     MetabaseDebug($this->database, "\tRemoved table '{$table_name}'");
                 } else {
                     if (isset($changes["TABLES"][$table_name]["name"])) {
                         MetabaseDebug($this->database, "\tRenamed table '{$table_name}' to '" . $changes["TABLES"][$table_name]["name"] . "'");
                     }
                     if (isset($changes["TABLES"][$table_name]["AddedFields"])) {
                         $fields = $changes["TABLES"][$table_name]["AddedFields"];
                         for ($field = 0, Reset($fields); $field < count($fields); $field++, Next($fields)) {
                             MetabaseDebug($this->database, "\tAdded field '" . Key($fields) . "'");
                         }
                     }
                     if (isset($changes["TABLES"][$table_name]["RemovedFields"])) {
                         $fields = $changes["TABLES"][$table_name]["RemovedFields"];
                         for ($field = 0, Reset($fields); $field < count($fields); $field++, Next($fields)) {
                             MetabaseDebug($this->database, "\tRemoved field '" . Key($fields) . "'");
                         }
                     }
                     if (isset($changes["TABLES"][$table_name]["RenamedFields"])) {
                         $fields = $changes["TABLES"][$table_name]["RenamedFields"];
                         for ($field = 0, Reset($fields); $field < count($fields); $field++, Next($fields)) {
                             MetabaseDebug($this->database, "\tRenamed field '" . Key($fields) . "' to '" . $fields[Key($fields)]["name"] . "'");
                         }
                     }
                     if (isset($changes["TABLES"][$table_name]["ChangedFields"])) {
                         $fields = $changes["TABLES"][$table_name]["ChangedFields"];
                         for ($field = 0, Reset($fields); $field < count($fields); $field++, Next($fields)) {
                             $field_name = Key($fields);
                             if (isset($fields[$field_name]["type"])) {
                                 MetabaseDebug($this->database, "\tChanged field '{$field_name}' type to '" . $fields[$field_name]["type"] . "'");
                             }
                             if (isset($fields[$field_name]["unsigned"])) {
                                 MetabaseDebug($this->database, "\tChanged field '{$field_name}' type to '" . ($fields[$field_name]["unsigned"] ? "" : "not ") . "unsigned'");
                             }
                             if (isset($fields[$field_name]["length"])) {
                                 MetabaseDebug($this->database, "\tChanged field '{$field_name}' length to '" . ($fields[$field_name]["length"] == 0 ? "no length" : $fields[$field_name]["length"]) . "'");
                             }
                             if (isset($fields[$field_name]["ChangedDefault"])) {
                                 MetabaseDebug($this->database, "\tChanged field '{$field_name}' default to " . (isset($fields[$field_name]["default"]) ? "'" . $fields[$field_name]["default"] . "'" : "NULL"));
                             }
                             if (isset($fields[$field_name]["ChangedNotNull"])) {
                                 MetabaseDebug($this->database, "\tChanged field '{$field_name}' notnull to " . (isset($fields[$field_name]["notnull"]) ? "'1'" : "0"));
                             }
                         }
                     }
                 }
             }
         }
     }
     if (isset($changes["SEQUENCES"])) {
         for ($change = 0, Reset($changes["SEQUENCES"]); $change < count($changes["SEQUENCES"]); Next($changes["SEQUENCES"]), $change++) {
             $sequence_name = Key($changes["SEQUENCES"]);
             MetabaseDebug($this->database, "{$sequence_name}:");
             if (isset($changes["SEQUENCES"][$sequence_name]["Add"])) {
                 MetabaseDebug($this->database, "\tAdded sequence '{$sequence_name}'");
             } else {
                 if (isset($changes["SEQUENCES"][$sequence_name]["Remove"])) {
                     MetabaseDebug($this->database, "\tRemoved sequence '{$sequence_name}'");
                 } else {
                     if (isset($changes["SEQUENCES"][$sequence_name]["name"])) {
                         MetabaseDebug($this->database, "\tRenamed sequence '{$sequence_name}' to '" . $changes["SEQUENCES"][$sequence_name]["name"] . "'");
                     }
                     if (isset($changes["SEQUENCES"][$sequence_name]["Change"])) {
                         $sequences = $changes["SEQUENCES"][$sequence_name]["Change"];
                         for ($sequence = 0, Reset($sequences); $sequence < count($sequences); $sequence++, Next($sequences)) {
                             $sequence_name = Key($sequences);
                             if (isset($sequences[$sequence_name]["start"])) {
                                 MetabaseDebug($this->database, "\tChanged sequence '{$sequence_name}' start to '" . $sequences[$sequence_name]["start"] . "'");
                             }
                         }
                     }
                 }
             }
         }
     }
     if (isset($changes["INDEXES"])) {
         for ($change = 0, Reset($changes["INDEXES"]); $change < count($changes["INDEXES"]); Next($changes["INDEXES"]), $change++) {
             $table_name = Key($changes["INDEXES"]);
             MetabaseDebug($this->database, "{$table_name}:");
             if (isset($changes["INDEXES"][$table_name]["AddedIndexes"])) {
                 $indexes = $changes["INDEXES"][$table_name]["AddedIndexes"];
                 for ($index = 0, Reset($indexes); $index < count($indexes); Next($indexes), $index++) {
                     MetabaseDebug($this->database, "\tAdded index '" . Key($indexes) . "' of table '{$table_name}'");
                 }
             }
             if (isset($changes["INDEXES"][$table_name]["RemovedIndexes"])) {
                 $indexes = $changes["INDEXES"][$table_name]["RemovedIndexes"];
                 for ($index = 0, Reset($indexes); $index < count($indexes); Next($indexes), $index++) {
                     MetabaseDebug($this->database, "\tRemoved index '" . Key($indexes) . "' of table '{$table_name}'");
                 }
             }
             if (isset($changes["INDEXES"][$table_name]["ChangedIndexes"])) {
                 $indexes = $changes["INDEXES"][$table_name]["ChangedIndexes"];
                 for ($index = 0, Reset($indexes); $index < count($indexes); Next($indexes), $index++) {
                     if (isset($indexes[Key($indexes)]["name"])) {
                         MetabaseDebug($this->database, "\tRenamed index '" . Key($indexes) . "' to '" . $indexes[Key($indexes)]["name"] . "' on table '{$table_name}'");
                     }
                     if (isset($indexes[Key($indexes)]["ChangedUnique"])) {
                         MetabaseDebug($this->database, "\tChanged index '" . Key($indexes) . "' unique to '" . isset($indexes[Key($indexes)]["unique"]) . "' on table '{$table_name}'");
                     }
                     if (isset($indexes[Key($indexes)]["ChangedFields"])) {
                         MetabaseDebug($this->database, "\tChanged index '" . Key($indexes) . "' on table '{$table_name}'");
                     }
                 }
             }
         }
     }
 }
示例#21
0
 function GetCredentials(&$credentials, $defaults, &$interactions)
 {
     Reset($credentials);
     $end = GetType($key = Key($credentials)) != "string";
     for (; !$end;) {
         if (!isset($this->credentials[$key])) {
             if (isset($defaults[$key])) {
                 $credentials[$key] = $defaults[$key];
             } else {
                 $this->error = "the requested credential " . $key . " is not defined";
                 return SASL_NOMECH;
             }
         } else {
             $credentials[$key] = $this->credentials[$key];
         }
         Next($credentials);
         $end = GetType($key = Key($credentials)) != "string";
     }
     return SASL_CONTINUE;
 }
示例#22
0
 function RestoreCookies($cookies, $clear = 1)
 {
     $new_cookies = $clear ? array() : $this->cookies;
     for ($secure_cookies = 0, Reset($cookies); $secure_cookies < count($cookies); Next($cookies), $secure_cookies++) {
         $secure = Key($cookies);
         if (GetType($secure) != "integer") {
             return $this->SetError("invalid cookie secure value type (" . serialize($secure) . ")");
         }
         for ($cookie_domain = 0, Reset($cookies[$secure]); $cookie_domain < count($cookies[$secure]); Next($cookies[$secure]), $cookie_domain++) {
             $domain_pattern = Key($cookies[$secure]);
             if (GetType($domain_pattern) != "string") {
                 return $this->SetError("invalid cookie domain value type (" . serialize($domain_pattern) . ")");
             }
             for (Reset($cookies[$secure][$domain_pattern]), $path_part = 0; $path_part < count($cookies[$secure][$domain_pattern]); Next($cookies[$secure][$domain_pattern]), $path_part++) {
                 $path = Key($cookies[$secure][$domain_pattern]);
                 if (GetType($path) != "string" || strcmp(substr($path, 0, 1), "/")) {
                     return $this->SetError("invalid cookie path value type (" . serialize($path) . ")");
                 }
                 for (Reset($cookies[$secure][$domain_pattern][$path]), $cookie = 0; $cookie < count($cookies[$secure][$domain_pattern][$path]); Next($cookies[$secure][$domain_pattern][$path]), $cookie++) {
                     $cookie_name = Key($cookies[$secure][$domain_pattern][$path]);
                     $expires = $cookies[$secure][$domain_pattern][$path][$cookie_name]["expires"];
                     $value = $cookies[$secure][$domain_pattern][$path][$cookie_name]["value"];
                     if (GetType($expires) != "string" || strlen($expires) && !preg_match("#^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\$#", $expires)) {
                         return $this->SetError("invalid cookie expiry value type (" . serialize($expires) . ")");
                     }
                     $new_cookies[$secure][$domain_pattern][$path][$cookie_name] = array("name" => $cookie_name, "value" => $value, "domain" => $domain_pattern, "path" => $path, "expires" => $expires, "secure" => $secure);
                 }
             }
         }
     }
     $this->cookies = $new_cookies;
     return "";
 }
示例#23
0
 function SetPropertyValues($ELEMENT_ID, $IBLOCK_ID, $PROPERTY_VALUES, $PROPERTY_CODE = false)
 {
     global $DB;
     $ELEMENT_ID = intVal($ELEMENT_ID);
     if (!is_array($PROPERTY_VALUES)) {
         $PROPERTY_VALUES = array($PROPERTY_VALUES);
     }
     $arFilter = array("IBLOCK_ID" => $IBLOCK_ID, "CHECK_PERMISSIONS" => "N");
     if ($PROPERTY_CODE !== false) {
         if (IntVal($PROPERTY_CODE) > 0) {
             $arFilter["ID"] = IntVal($PROPERTY_CODE);
         } else {
             $arFilter["CODE"] = $PROPERTY_CODE;
         }
     } else {
         $arFilter["ACTIVE"] = "Y";
     }
     $uniq_flt = md5(serialize($arFilter));
     global $BX_IBLOCK_PROP_CACHE;
     if (!is_set($BX_IBLOCK_PROP_CACHE, $IBLOCK_ID)) {
         $BX_IBLOCK_PROP_CACHE[$IBLOCK_ID] = array();
     }
     if (is_set($BX_IBLOCK_PROP_CACHE[$IBLOCK_ID], $uniq_flt)) {
         $ar_prop =& $BX_IBLOCK_PROP_CACHE[$IBLOCK_ID][$uniq_flt];
     } else {
         $db_prop = CIBlockProperty::GetList(array(), $arFilter);
         $ar_prop = array();
         while ($prop = $db_prop->Fetch()) {
             $ar_prop[] = $prop;
         }
         $BX_IBLOCK_PROP_CACHE[$IBLOCK_ID][$uniq_flt] =& $ar_prop;
     }
     Reset($ar_prop);
     $bRecalcSections = false;
     $arPROP_ID = array_keys($PROPERTY_VALUES);
     $cacheValues = false;
     if (count($ar_prop) > 1) {
         $cacheValues = array();
         $strSql = "SELECT ep.ID, ep.VALUE, ep.IBLOCK_PROPERTY_ID " . "FROM b_iblock_element_property ep, b_iblock_property p " . "WHERE ep.IBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\tAND ep.IBLOCK_PROPERTY_ID = p.ID " . "\tAND p.PROPERTY_TYPE <> 'L' " . "\tAND p.PROPERTY_TYPE <> 'G' ";
         $db_res = $DB->Query($strSql);
         while ($res = $db_res->Fetch()) {
             if (!isset($cacheValues[$res["IBLOCK_PROPERTY_ID"]])) {
                 $cacheValues[$res["IBLOCK_PROPERTY_ID"]] = array();
             }
             $cacheValues[$res["IBLOCK_PROPERTY_ID"]][] = $res;
         }
     }
     $ids = "0";
     foreach ($ar_prop as $prop) {
         if ($PROPERTY_CODE) {
             $PROP = $PROPERTY_VALUES;
         } else {
             if (strlen($prop["CODE"]) > 0 && in_array($prop["CODE"], $arPROP_ID, TRUE)) {
                 $PROP = $PROPERTY_VALUES[$prop["CODE"]];
             } else {
                 $PROP = $PROPERTY_VALUES[$prop["ID"]];
             }
         }
         if ($prop["PROPERTY_TYPE"] == "F") {
             if (!is_array($PROP) || is_array($PROP) && (is_set($PROP, "tmp_name") || is_set($PROP, "del")) || count($PROP) == 2 && is_set($PROP, "VALUE") && is_set($PROP, "DESCRIPTION")) {
                 $PROP = array($PROP);
             }
         } elseif (!is_array($PROP) || count($PROP) == 2 && is_set($PROP, "VALUE") && is_set($PROP, "DESCRIPTION")) {
             $PROP = array($PROP);
         }
         if ($prop["USER_TYPE"] != "") {
             $arUserType = CIBlockProperty::GetUserType($prop["USER_TYPE"]);
             if (array_key_exists("ConvertToDB", $arUserType)) {
                 foreach ($PROP as $key => $value) {
                     if (!is_array($value)) {
                         $value = array("VALUE" => $value);
                     } elseif (!array_key_exists("VALUE", $value)) {
                         $value = array("VALUE" => $value);
                     }
                     $PROP[$key] = call_user_func_array($arUserType["ConvertToDB"], array($prop, $value));
                 }
             }
         }
         if ($prop["VERSION"] == 2) {
             if ($prop["MULTIPLE"] == "Y") {
                 $strTable = "b_iblock_element_prop_m" . $prop["IBLOCK_ID"];
             } else {
                 $strTable = "b_iblock_element_prop_s" . $prop["IBLOCK_ID"];
             }
         } else {
             $strTable = "b_iblock_element_property";
         }
         if ($prop["PROPERTY_TYPE"] == "L") {
             $DB->Query(CIBLockElement::DeletePropertySQL($prop, $ELEMENT_ID), false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
             if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") {
                 $strSql = "\n\t\t\t\t\t\tUPDATE\tb_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\tSET\tPROPERTY_" . $prop["ID"] . "=NULL, DESCRIPTION_" . $prop["ID"] . "=NULL\n\t\t\t\t\t\tWHERE\tIBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t";
                 $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
             }
             $ids = "0";
             foreach ($PROP as $key => $value) {
                 if (is_array($value)) {
                     $value = $value["VALUE"];
                 }
                 if (IntVal($value) <= 0) {
                     continue;
                 }
                 $ids .= "," . IntVal($value);
                 if ($prop["MULTIPLE"] != "Y") {
                     break;
                 }
             }
             if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") {
                 $strSql = "\n\t\t\t\t\t\tUPDATE\n\t\t\t\t\t\t\tb_iblock_element_prop_s" . $prop["IBLOCK_ID"] . " E\n\t\t\t\t\t\t\t,b_iblock_property P\n\t\t\t\t\t\t\t,b_iblock_property_enum PEN\n\t\t\t\t\t\tSET\n\t\t\t\t\t\t\tE.PROPERTY_" . $prop["ID"] . "=PEN.ID\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tE.IBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t\t\tAND P.ID=" . $prop["ID"] . "\n\t\t\t\t\t\t\tAND P.ID=PEN.PROPERTY_ID\n\t\t\t\t\t\t\tAND PEN.ID IN (" . $ids . ")\n\t\t\t\t\t";
             } else {
                 $strSql = "\n\t\t\t\t\t\tINSERT INTO " . $strTable . "\n\t\t\t\t\t\t(IBLOCK_ELEMENT_ID, IBLOCK_PROPERTY_ID, VALUE, VALUE_ENUM)\n\t\t\t\t\t\tSELECT " . $ELEMENT_ID . ", P.ID, PEN.ID, PEN.ID\n\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\tb_iblock_property P\n\t\t\t\t\t\t\t,b_iblock_property_enum PEN\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tP.ID=" . $prop["ID"] . "\n\t\t\t\t\t\t\tAND P.ID=PEN.PROPERTY_ID\n\t\t\t\t\t\t\tAND PEN.ID IN (" . $ids . ")\n\t\t\t\t\t";
             }
             $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         } elseif ($prop["PROPERTY_TYPE"] == "G") {
             $bRecalcSections = true;
             $DB->Query(CIBLockElement::DeletePropertySQL($prop, $ELEMENT_ID), false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
             if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") {
                 $strSql = "\n\t\t\t\t\t\tUPDATE\tb_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\tSET\tPROPERTY_" . $prop["ID"] . "=NULL, DESCRIPTION_" . $prop["ID"] . "=NULL\n\t\t\t\t\t\tWHERE\tIBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t";
                 $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
             }
             $DB->Query("DELETE FROM b_iblock_section_element WHERE ADDITIONAL_PROPERTY_ID=" . $prop["ID"] . " AND IBLOCK_ELEMENT_ID=" . $ELEMENT_ID, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
             $ids = "0";
             foreach ($PROP as $key => $value) {
                 if (is_array($value)) {
                     $value = $value["VALUE"];
                 }
                 if (IntVal($value) <= 0) {
                     continue;
                 }
                 $ids .= "," . IntVal($value);
                 if ($prop["MULTIPLE"] != "Y") {
                     break;
                 }
             }
             if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") {
                 $strSql = "\n\t\t\t\t\t\tUPDATE\n\t\t\t\t\t\t\tb_iblock_element_prop_s" . $prop["IBLOCK_ID"] . " E\n\t\t\t\t\t\t\t,b_iblock_property P\n\t\t\t\t\t\t\t,b_iblock_section S\n\t\t\t\t\t\tSET\n\t\t\t\t\t\t\tE.PROPERTY_" . $prop["ID"] . "=S.ID\n\t\t\t\t\t\t\t,DESCRIPTION_" . $prop["ID"] . "=null\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tE.IBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t\t\tAND P.ID=" . $prop["ID"] . "\n\t\t\t\t\t\t\tAND S.IBLOCK_ID = P.LINK_IBLOCK_ID\n\t\t\t\t\t\t\tAND S.ID IN (" . $ids . ")\n\t\t\t\t\t";
             } else {
                 $strSql = "\n\t\t\t\t\t\tINSERT INTO " . $strTable . "\n\t\t\t\t\t\t(IBLOCK_ELEMENT_ID, IBLOCK_PROPERTY_ID, VALUE, VALUE_NUM)\n\t\t\t\t\t\tSELECT " . $ELEMENT_ID . ", P.ID, S.ID, S.ID\n\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\tb_iblock_property P\n\t\t\t\t\t\t\t,b_iblock_section S\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tP.ID=" . $prop["ID"] . "\n\t\t\t\t\t\t\tAND S.IBLOCK_ID = P.LINK_IBLOCK_ID\n\t\t\t\t\t\t\tAND S.ID IN (" . $ids . ")\n\t\t\t\t\t";
             }
             $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
             $DB->Query("INSERT INTO b_iblock_section_element(IBLOCK_ELEMENT_ID, IBLOCK_SECTION_ID, ADDITIONAL_PROPERTY_ID) " . "SELECT " . $ELEMENT_ID . ", S.ID, P.ID " . "FROM b_iblock_property P, b_iblock_section S " . "WHERE P.ID=" . $prop["ID"] . " " . "\tAND S.IBLOCK_ID = P.LINK_IBLOCK_ID " . "\tAND S.ID IN (" . $ids . ") ", false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         } else {
             $ids = "0";
             $arV = array();
             if ($cacheValues === false || $prop["VERSION"] == 2) {
                 if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") {
                     $strSql = "\n\t\t\t\t\t\t\tSELECT\tconcat(IBLOCK_ELEMENT_ID,':','" . $prop["ID"] . "') ID, PROPERTY_" . $prop["ID"] . " VALUE\n\t\t\t\t\t\t\tFROM\tb_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\tWHERE\tIBLOCK_ELEMENT_ID=" . $ELEMENT_ID;
                 } else {
                     $strSql = "\n\t\t\t\t\t\t\tSELECT\tID, VALUE\n\t\t\t\t\t\t\tFROM\t" . $strTable . "\n\t\t\t\t\t\t\tWHERE\tIBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t\t\t\tAND IBLOCK_PROPERTY_ID=" . $prop["ID"];
                 }
                 $db_res = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
                 while ($res = $db_res->Fetch()) {
                     $arV[] = $res;
                 }
             } elseif (is_set($cacheValues, $prop["ID"])) {
                 $arV = $cacheValues[$prop["ID"]];
             }
             $arWas = array();
             foreach ($arV as $res) {
                 $val = $PROP[$res["ID"]];
                 if (is_array($val) && !is_set($val, "tmp_name") && !is_set($val, "del")) {
                     $val_desc = $val["DESCRIPTION"];
                     $val = $val["VALUE"];
                 } else {
                     $val_desc = false;
                 }
                 if ($prop["PROPERTY_TYPE"] == "E") {
                     if (in_array($val, $arWas)) {
                         $val = "";
                     } else {
                         $arWas[] = $val;
                     }
                 }
                 if ($prop["PROPERTY_TYPE"] == "S" || $prop["PROPERTY_TYPE"] == "N" || $prop["PROPERTY_TYPE"] == "E") {
                     if (strlen($val) <= 0) {
                         if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") {
                             $strSql = "\n\t\t\t\t\t\t\t\t\tUPDATE\tb_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t\t\t\tPROPERTY_" . $prop["ID"] . "=null\n\t\t\t\t\t\t\t\t\t\t,DESCRIPTION_" . $prop["ID"] . "=null\n\t\t\t\t\t\t\t\t\tWHERE\tIBLOCK_ELEMENT_ID=" . $ELEMENT_ID;
                         } else {
                             $strSql = "DELETE FROM " . $strTable . " WHERE ID=" . $res["ID"];
                         }
                         $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
                         if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") {
                             $strSql = "\n\t\t\t\t\t\t\t\t\tUPDATE\tb_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\t\tSET\tPROPERTY_" . $prop["ID"] . "=NULL, DESCRIPTION_" . $prop["ID"] . "=NULL\n\t\t\t\t\t\t\t\t\tWHERE\tIBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t\t\t\t";
                             $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
                         }
                     } else {
                         if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") {
                             if ($prop["PROPERTY_TYPE"] == "N") {
                                 $val = CIBlock::roundDB($val);
                             }
                             $strSql = "\n\t\t\t\t\t\t\t\t\tUPDATE b_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\t\tSET PROPERTY_" . $prop["ID"] . "='" . $DB->ForSql($val) . "'\n\t\t\t\t\t\t\t\t\t,DESCRIPTION_" . $prop["ID"] . "=" . ($val_desc !== false ? "'" . $DB->ForSQL($val_desc, 255) . "'" : "null") . "\n\t\t\t\t\t\t\t\t\tWHERE IBLOCK_ELEMENT_ID=" . $ELEMENT_ID;
                         } else {
                             $strSql = "\n\t\t\t\t\t\t\t\t\tUPDATE " . $strTable . "\n\t\t\t\t\t\t\t\t\tSET \tVALUE='" . $DB->ForSql($val) . "'\n\t\t\t\t\t\t\t\t\t\t,VALUE_NUM=" . CIBlock::roundDB($val) . "\n\t\t\t\t\t\t\t\t\t\t" . ($val_desc !== false ? ",DESCRIPTION='" . $DB->ForSql($val_desc, 255) . "'" : "") . "\n\t\t\t\t\t\t\t\t\tWHERE ID=" . $res["ID"];
                         }
                         $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
                         if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") {
                             $strSql = "\n\t\t\t\t\t\t\t\t\tUPDATE\tb_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\t\tSET\tPROPERTY_" . $prop["ID"] . "=NULL, DESCRIPTION_" . $prop["ID"] . "=NULL\n\t\t\t\t\t\t\t\t\tWHERE\tIBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t\t\t\t";
                             $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
                         }
                     }
                 } elseif ($prop["PROPERTY_TYPE"] == "F") {
                     if (is_array($val)) {
                         if (strlen($val["del"]) > 0) {
                             $val = "NULL";
                         } else {
                             $val["MODULE_ID"] = "iblock";
                             if ($val_desc !== false) {
                                 $val["description"] = $val_desc;
                             }
                             if ($val_desc !== false && strlen($val["name"]) <= 0) {
                                 //update description only
                                 if ($res["VALUE"] > 0) {
                                     CFile::UpdateDesc($res["VALUE"], $val_desc);
                                 }
                                 $val = false;
                             } else {
                                 //register new file
                                 $val = CFile::SaveFile($val, "iblock");
                             }
                         }
                     }
                     if ($val == "NULL") {
                         CIBLockElement::DeleteFile($res["VALUE"], $ELEMENT_ID, "PROPERTY", -1, $prop["IBLOCK_ID"]);
                         if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") {
                             $strSql = "\n\t\t\t\t\t\t\t\t\tUPDATE b_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\t\tSET PROPERTY_" . $prop["ID"] . "=null\n\t\t\t\t\t\t\t\t\t,DESCRIPTION_" . $prop["ID"] . "=null\n\t\t\t\t\t\t\t\t\tWHERE IBLOCK_ELEMENT_ID=" . $ELEMENT_ID;
                         } else {
                             $strSql = "DELETE FROM " . $strTable . " WHERE ID=" . $res["ID"];
                         }
                         $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
                         if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") {
                             $strSql = "\n\t\t\t\t\t\t\t\t\tUPDATE\tb_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\t\tSET\tPROPERTY_" . $prop["ID"] . "=NULL, DESCRIPTION_" . $prop["ID"] . "=NULL\n\t\t\t\t\t\t\t\t\tWHERE\tIBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t\t\t\t";
                             $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
                         }
                     } elseif (IntVal($val) > 0) {
                         if (intval($val) != $res["VALUE"]) {
                             CIBLockElement::DeleteFile($res["VALUE"], $ELEMENT_ID, "PROPERTY", -1, $prop["IBLOCK_ID"]);
                         }
                         if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") {
                             $strSql = "\n\t\t\t\t\t\t\t\t\tUPDATE b_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\t\tSET PROPERTY_" . $prop["ID"] . "='" . intval($val) . "'\n\t\t\t\t\t\t\t\t\t" . ($val_desc !== false ? ",DESCRIPTION_" . $prop["ID"] . "='" . $DB->ForSql($val_desc, 255) . "'" : "") . "\n\t\t\t\t\t\t\t\t\tWHERE IBLOCK_ELEMENT_ID=" . $ELEMENT_ID;
                         } else {
                             $strSql = "\n\t\t\t\t\t\t\t\t\tUPDATE " . $strTable . "\n\t\t\t\t\t\t\t\t\tSET \tVALUE='" . intval($val) . "'\n\t\t\t\t\t\t\t\t\t\t,VALUE_NUM='" . intval($val) . "'\n\t\t\t\t\t\t\t\t\t\t" . ($val_desc !== false ? ",DESCRIPTION='" . $DB->ForSql($val_desc, 255) . "'" : "") . "\n\t\t\t\t\t\t\t\t\tWHERE ID=" . $res["ID"];
                         }
                         $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
                         if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") {
                             $strSql = "\n\t\t\t\t\t\t\t\t\tUPDATE\tb_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\t\tSET\tPROPERTY_" . $prop["ID"] . "=NULL, DESCRIPTION_" . $prop["ID"] . "=NULL\n\t\t\t\t\t\t\t\t\tWHERE\tIBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t\t\t\t";
                             $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
                         }
                     } elseif ($val_desc !== false) {
                         if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") {
                             $strSql = "\n\t\t\t\t\t\t\t\t\tUPDATE b_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\t\tSET DESCRIPTION_" . $prop["ID"] . "='" . $DB->ForSql($val_desc, 255) . "'\n\t\t\t\t\t\t\t\t\tWHERE IBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t\t\t\t";
                         } else {
                             $strSql = "\n\t\t\t\t\t\t\t\t\tUPDATE " . $strTable . "\n\t\t\t\t\t\t\t\t\tSET DESCRIPTION='" . $DB->ForSql($val_desc, 255) . "'\n\t\t\t\t\t\t\t\t\tWHERE ID=" . $res["ID"] . "\n\t\t\t\t\t\t\t\t";
                         }
                         $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
                         if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") {
                             $strSql = "\n\t\t\t\t\t\t\t\t\tUPDATE\tb_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\t\tSET\tPROPERTY_" . $prop["ID"] . "=NULL, DESCRIPTION_" . $prop["ID"] . "=NULL\n\t\t\t\t\t\t\t\t\tWHERE\tIBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t\t\t\t";
                             $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
                         }
                     }
                 }
                 $ids .= "," . $res["ID"];
                 unset($PROP[$res["ID"]]);
             }
             //foreach($arV as $res)
             foreach ($PROP as $key => $val) {
                 if (is_array($val) && !is_set($val, "tmp_name")) {
                     $val_desc = $val["DESCRIPTION"];
                     $val = $val["VALUE"];
                 } else {
                     $val_desc = false;
                 }
                 if ($prop["PROPERTY_TYPE"] == "F") {
                     if (is_array($val)) {
                         $val["MODULE_ID"] = "iblock";
                         if ($val_desc !== false) {
                             $val["description"] = $val_desc;
                         }
                         $val = CFile::SaveFile($val, "iblock");
                     }
                     if (intval($val) <= 0) {
                         $val = false;
                     } elseif ($prop["MULTIPLE"] != "Y" && strlen($val) > 0) {
                         $strSql = "\n\t\t\t\t\t\t\t\tSELECT VALUE\n\t\t\t\t\t\t\t\tFROM b_iblock_element_property\n\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\tIBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t\t\t\t\tAND IBLOCK_PROPERTY_ID=" . IntVal($prop["ID"]) . "\n\t\t\t\t\t\t\t";
                         if ($prop["VERSION"] == 2) {
                             if ($prop["MULTIPLE"] == "Y") {
                                 $strSql = "\n\t\t\t\t\t\t\t\t\t\tSELECT PROPERTY_" . $prop["ID"] . " VALUE\n\t\t\t\t\t\t\t\t\t\tFROM b_iblock_element_prop_m" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\tIBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t\t\t\t\t\tAND IBLOCK_PROPERTY_ID=" . IntVal($prop["ID"]) . "\n\t\t\t\t\t\t\t\t\t";
                             } else {
                                 $strSql = "\n\t\t\t\t\t\t\t\t\t\tSELECT PROPERTY_" . $prop["ID"] . " VALUE\n\t\t\t\t\t\t\t\t\t\tFROM b_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\t\t\tWHERE IBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t\t\t\t\t";
                             }
                         }
                         $pfres = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
                         while ($pfar = $pfres->Fetch()) {
                             CIBLockElement::DeleteFile($pfar["VALUE"], $ELEMENT_ID, "PROPERTY", -1, $prop["IBLOCK_ID"]);
                         }
                         $DB->Query(CIBLockElement::DeletePropertySQL($prop, $ELEMENT_ID), false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
                         if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") {
                             $strSql = "\n\t\t\t\t\t\t\t\t\tUPDATE\tb_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\t\tSET\tPROPERTY_" . $prop["ID"] . "=NULL, DESCRIPTION_" . $prop["ID"] . "=NULL\n\t\t\t\t\t\t\t\t\tWHERE\tIBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t\t\t\t";
                             $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
                         }
                     }
                 } elseif ($prop["PROPERTY_TYPE"] == "E") {
                     if (in_array($val, $arWas)) {
                         $val = "";
                     } else {
                         $arWas[] = $val;
                     }
                 }
                 if (strlen($val) > 0) {
                     if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "N") {
                         $strSql = "\n\t\t\t\t\t\t\t\tUPDATE\tb_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t\t\tPROPERTY_" . $prop["ID"] . " = '" . $DB->ForSql($val) . "'\n\t\t\t\t\t\t\t\t\t,DESCRIPTION_" . $prop["ID"] . "=" . ($val_desc !== false ? "'" . $DB->ForSQL($val_desc, 255) . "'" : "null") . "\n\t\t\t\t\t\t\t\tWHERE\tIBLOCK_ELEMENT_ID=" . $ELEMENT_ID;
                     } else {
                         $strSql = "\n\t\t\t\t\t\t\t\tINSERT INTO " . $strTable . "\n\t\t\t\t\t\t\t\t(IBLOCK_ELEMENT_ID, IBLOCK_PROPERTY_ID, VALUE, VALUE_NUM" . ($val_desc !== false ? ", DESCRIPTION" : "") . ")\n\t\t\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t\t\t" . $ELEMENT_ID . "\n\t\t\t\t\t\t\t\t\t,P.ID\n\t\t\t\t\t\t\t\t\t,'" . $DB->ForSql($val) . "'\n\t\t\t\t\t\t\t\t\t," . CIBlock::roundDB($val) . "\n\t\t\t\t\t\t\t\t\t" . ($val_desc !== false ? ", '" . $DB->ForSQL($val_desc, 255) . "'" : "") . "\n\t\t\t\t\t\t\t\tFROM\tb_iblock_property P\n\t\t\t\t\t\t\t\tWHERE\tID=" . IntVal($prop["ID"]);
                     }
                     $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
                     if ($prop["VERSION"] == 2 && $prop["MULTIPLE"] == "Y") {
                         $strSql = "\n\t\t\t\t\t\t\t\tUPDATE\tb_iblock_element_prop_s" . $prop["IBLOCK_ID"] . "\n\t\t\t\t\t\t\t\tSET\tPROPERTY_" . $prop["ID"] . "=NULL, DESCRIPTION_" . $prop["ID"] . "=NULL\n\t\t\t\t\t\t\t\tWHERE\tIBLOCK_ELEMENT_ID=" . $ELEMENT_ID . "\n\t\t\t\t\t\t\t";
                         $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
                     }
                     if ($prop["MULTIPLE"] != "Y") {
                         break;
                     }
                 }
                 $ids .= "," . $prop["ID"];
             }
             //foreach($PROP as $key=>$value)
         }
         //if($prop["PROPERTY_TYPE"]=="L")
     }
     if ($bRecalcSections) {
         CIBlockElement::RecalcSections($ELEMENT_ID);
     }
     /****************************** QUOTA ******************************/
     $_SESSION["SESS_RECOUNT_DB"] = "Y";
     /****************************** QUOTA ******************************/
 }
示例#24
0
if (!$mime->Decode($parameters, $decoded)) {
    echo 'MIME message decoding error: ' . $mime->error . ' at position ' . $mime->error_position;
    if ($mime->track_lines && $mime->GetPositionLine($mime->error_position, $line, $column)) {
        echo ' line ' . $line . ' column ' . $column;
    }
    echo "\n";
} else {
    print_r($decoded);
    die;
    echo 'MIME message decoding successful.' . "\n";
    echo count($decoded) == 1 ? '1 message was found.' : count($decoded) . ' messages were found.', "\n";
    for ($message = 0; $message < count($decoded); $message++) {
        echo 'Message ', $message + 1, ':', "\n";
        var_dump($decoded[$message]);
        if ($mime->decode_bodies) {
            if ($mime->Analyze($decoded[$message], $results)) {
                var_dump($results);
            } else {
                echo 'MIME message analyse error: ' . $mime->error . "\n";
            }
        }
    }
    for ($warning = 0, Reset($mime->warnings); $warning < count($mime->warnings); Next($mime->warnings), $warning++) {
        $w = Key($mime->warnings);
        echo 'Warning: ', $mime->warnings[$w], ' at position ', $w;
        if ($mime->track_lines && $mime->GetPositionLine($w, $line, $column)) {
            echo ' line ' . $line . ' column ' . $column;
        }
        echo "\n";
    }
}
示例#25
0
 protected function _sendHttp($post_values, $uri)
 {
     /*
       This function Copyright (C) 2005-2006 Thomas Harding, Manuel Lemos
     */
     $this->response_completed[] = "no";
     unset($this->serverouptut);
     self::_putDebug(_("Processing HTTP request"), 2);
     $this->serveroutput->headers = array();
     $this->serveroutput->body = "";
     $http = new http_class();
     if (!$this->unix) {
         $http->host = $this->host;
     } else {
         $http->host = "localhost";
     }
     $http->with_exceptions = $this->with_exceptions;
     if ($this->debug_http) {
         $http->debug = 1;
         $http->html_debug = 0;
     } else {
         $http->debug = 0;
         $http->html_debug = 0;
     }
     $url = "http://" . $this->host;
     if ($this->ssl) {
         $url = "https://" . $this->host;
     }
     if ($this->unix) {
         $url = "unix://" . $this->host;
     }
     $http->port = $this->port;
     $http->timeout = $this->http_timeout;
     $http->data_timeout = $this->http_data_timeout;
     $http->force_multipart_form_post = false;
     $http->user = $this->username;
     $http->password = $this->password;
     $error = $http->GetRequestArguments($url, $arguments);
     $arguments["RequestMethod"] = "POST";
     $arguments["Headers"] = array("Content-Type" => "application/ipp");
     $arguments["BodyStream"] = array(array("Data" => $post_values["Data"]));
     if (isset($post_values["File"])) {
         $arguments["BodyStream"][] = array("File" => $post_values["File"]);
     }
     if (isset($post_values["FileType"]) && !strcmp($post_values["FileType"], "TEXT")) {
         $arguments["BodyStream"][] = array("Data" => Chr(12));
     }
     $arguments["RequestURI"] = $uri;
     if ($this->with_exceptions && $this->handle_http_exceptions) {
         try {
             $success = $http->Open($arguments);
         } catch (httpException $e) {
             throw new ippException(sprintf("http error: %s", $e->getMessage()), $e->getErrno());
         }
     } else {
         $success = $http->Open($arguments);
     }
     if ($success[0] == true) {
         $success = $http->SendRequest($arguments);
         if ($success[0] == true) {
             self::_putDebug("H T T P    R E Q U E S T :");
             self::_putDebug("Request headers:");
             for (Reset($http->request_headers), $header = 0; $header < count($http->request_headers); Next($http->request_headers), $header++) {
                 $header_name = Key($http->request_headers);
                 if (GetType($http->request_headers[$header_name]) == "array") {
                     for ($header_value = 0; $header_value < count($http->request_headers[$header_name]); $header_value++) {
                         self::_putDebug($header_name . ": " . $http->request_headers[$header_name][$header_value]);
                     }
                 } else {
                     self::_putDebug($header_name . ": " . $http->request_headers[$header_name]);
                 }
             }
             self::_putDebug("Request body:");
             self::_putDebug(htmlspecialchars($http->request_body) . "*********** END REQUEST BODY *********");
             $i = 0;
             $headers = array();
             unset($this->serveroutput->headers);
             $http->ReadReplyHeaders($headers);
             self::_putDebug("H T T P    R E S P O N S E :");
             self::_putDebug("Response headers:");
             for (Reset($headers), $header = 0; $header < count($headers); Next($headers), $header++) {
                 $header_name = Key($headers);
                 if (GetType($headers[$header_name]) == "array") {
                     for ($header_value = 0; $header_value < count($headers[$header_name]); $header_value++) {
                         self::_putDebug($header_name . ": " . $headers[$header_name][$header_value]);
                         $this->serveroutput->headers[$i] = $header_name . ": " . $headers[$header_name][$header_value];
                         $i++;
                     }
                 } else {
                     self::_putDebug($header_name . ": " . $headers[$header_name]);
                     $this->serveroutput->headers[$i] = $header_name . ": " . $headers[$header_name];
                     $i++;
                 }
             }
             self::_putDebug("\n\nResponse body:\n");
             $this->serveroutput->body = "";
             for (;;) {
                 $http->ReadReplyBody($body, 1024);
                 if (strlen($body) == 0) {
                     break;
                 }
                 self::_putDebug(htmlentities($body));
                 $this->serveroutput->body .= $body;
             }
             self::_putDebug("********* END RESPONSE BODY ********");
         }
     }
     $http->Close();
     return true;
 }
示例#26
0
 function CreateIndex(&$db, $table, $name, &$definition)
 {
     $query = "CREATE " . (isset($definition["unique"]) ? "UNIQUE" : "") . " INDEX {$name} ON {$table} (";
     for ($field = 0, Reset($definition["FIELDS"]); $field < count($definition["FIELDS"]); $field++, Next($definition["FIELDS"])) {
         if ($field > 0) {
             $query .= ",";
         }
         $query .= Key($definition["FIELDS"]);
     }
     $query .= ")";
     return $db->Query($query);
 }
示例#27
0
 function OpenMailing(&$mailing, &$mailing_properties)
 {
     if (strlen($this->error)) {
         return $this->error;
     }
     if (!isset($mailing_properties["Name"]) || strlen($mailing_properties["Name"]) == 0) {
         return $this->OutputError("it was not specified a valid mailing Name");
     }
     if (!isset($mailing_properties["Return-Path"]) || strlen($mailing_properties["Return-Path"]) == 0) {
         return $this->OutputError("it was not specified a valid mailing Return-Path");
     }
     $separator = "";
     $directory_separator = defined("DIRECTORY_SEPARATOR") ? DIRECTORY_SEPARATOR : (defined("PHP_OS") && !strcmp(substr(PHP_OS, 0, 3), "WIN") ? "\\" : "/");
     $length = strlen($this->mailing_path);
     if ($length) {
         if ($this->mailing_path[$length - 1] != $directory_separator) {
             $separator = $directory_separator;
         }
     }
     $base_path = $this->mailing_path . $separator . $mailing_properties["Name"];
     if ($this->body_parts == 0) {
         return $this->OutputError("message has no body parts");
     }
     $line_break = "\n";
     $headers = $this->headers;
     if (strlen($this->mailer)) {
         $headers["X-Mailer"] = $this->mailer;
     }
     $headers["MIME-Version"] = "1.0";
     if (strlen($error = $this->GetPartHeaders($headers, $this->body))) {
         return $error;
     }
     if (!($header_file = @fopen($base_path . ".h", "wb"))) {
         return $this->OutputPHPError("could not open mailing headers file " . $base_path . ".h", $php_errormsg);
     }
     for ($header = 0, Reset($headers); $header < count($headers); Next($headers), ++$header) {
         $header_name = Key($headers);
         if (!@fwrite($header_file, $header_name . ": " . $headers[$header_name] . $line_break)) {
             fclose($header_file);
             return $this->OutputPHPError("could not write to the mailing headers file " . $base_path . ".h", $php_errormsg);
         }
     }
     if (!@fflush($header_file)) {
         fclose($header_file);
         @unlink($base_path . ".h");
         return $this->OutputPHPError("could not write to the mailing headers file " . $base_path . ".h", $php_errormsg);
     }
     fclose($header_file);
     if (strlen($error = $this->GetPartBody($body, $this->body))) {
         @unlink($base_path . ".h");
         return $error;
     }
     if (!($body_file = @fopen($base_path . ".b", "wb"))) {
         @unlink($base_path . ".h");
         return $this->OutputPHPError("could not open mailing body file " . $base_path . ".b", $php_errormsg);
     }
     if (!@fwrite($body_file, $body) || !@fflush($body_file)) {
         fclose($body_file);
         @unlink($base_path . ".b");
         @unlink($base_path . ".h");
         return $this->OutputPHPError("could not write to the mailing body file " . $base_path . ".b", $php_errormsg);
     }
     fclose($body_file);
     if (!($envelope = @fopen($base_path . ".e", "wb"))) {
         @unlink($base_path . ".b");
         @unlink($base_path . ".h");
         return $this->OutputPHPError("could not open mailing envelope file " . $base_path . ".e", $php_errormsg);
     }
     if (!@fwrite($envelope, "F" . $mailing_properties["Return-Path"] . chr(0)) || !@fflush($envelope)) {
         @fclose($envelope);
         @unlink($base_path . ".e");
         @unlink($base_path . ".b");
         @unlink($base_path . ".h");
         return $this->OutputPHPError("could not write to the return path to the mailing envelope file " . $base_path . ".e", $php_errormsg);
     }
     $mailing = ++$this->last_mailing;
     $this->mailings[$mailing] = array("Envelope" => $envelope, "BasePath" => $base_path);
     return "";
 }
示例#28
0
 function SendMessageHeaders($headers)
 {
     $header_data = "";
     //$date=date("D, d M Y H:i:s T");
     $date = date("D, d M Y H:i:s O");
     if ($this->smtp_direct_delivery && strlen($this->localhost)) {
         $local_ip = gethostbyname($this->localhost);
         $header_data .= $this->FormatHeader("Received", "FROM " . $this->localhost . " ([" . $local_ip . "]) BY " . $this->localhost . " ([" . $local_ip . "]) WITH SMTP; " . $date) . "\r\n";
     }
     for ($message_id_set = $date_set = 0, $header = 0, $return_path = $from = $to = $recipients = array(), Reset($headers); $header < count($headers); $header++, Next($headers)) {
         $header_name = Key($headers);
         switch (strtolower($header_name)) {
             case "return-path":
                 $return_path[$headers[$header_name]] = 1;
                 break;
             case "from":
                 $error = $this->GetRFC822Addresses($headers[$header_name], $from);
                 break;
             case "to":
                 $error = $this->GetRFC822Addresses($headers[$header_name], $to);
                 break;
             case "cc":
             case "bcc":
                 $this->GetRFC822Addresses($headers[$header_name], $recipients);
                 break;
             case "date":
                 $date_set = 1;
                 break;
             case "message-id":
                 $message_id_set = 1;
                 break;
         }
         if (strcmp($error, "")) {
             return $this->OutputError($error);
         }
         if (strtolower($header_name) == "bcc") {
             continue;
         }
         $header_data .= $this->FormatHeader($header_name, $headers[$header_name]) . "\r\n";
     }
     if (count($from) == 0) {
         return $this->OutputError("it was not specified a valid From header");
     }
     if (count($to) == 0) {
         return $this->OutputError("it was not specified a valid To header");
     }
     Reset($return_path);
     Reset($from);
     $this->invalid_recipients = array();
     if (!$this->smtp->MailFrom(count($return_path) ? Key($return_path) : Key($from)) || !$this->SetRecipients($to, $valid_recipients)) {
         return $this->OutputError($this->smtp->error);
     }
     if ($valid_recipients == 0) {
         return $this->OutputError("it were not specified any valid recipients");
     }
     if (!$date_set) {
         $header_data .= "Date: " . $date . "\r\n";
     }
     if (!$message_id_set && $this->auto_message_id) {
         $sender = count($return_path) ? Key($return_path) : Key($from);
         $header_data .= $this->GenerateMessageID($sender) . "\r\n";
     }
     if (!$this->SetRecipients($recipients, $valid_recipients) || !$this->smtp->StartData() || !$this->smtp->SendData($header_data . "\r\n")) {
         return $this->OutputError($this->smtp->error);
     }
     return "";
 }
示例#29
0
 function Replace($table, &$fields)
 {
     $count = count($fields);
     for ($keys = 0, $query = $values = "", Reset($fields), $field = 0; $field < $count; Next($fields), $field++) {
         $name = Key($fields);
         if ($field > 0) {
             $query .= ",";
             $values .= ",";
         }
         $query .= $name;
         if (isset($fields[$name]["Null"]) && $fields[$name]["Null"]) {
             $value = "NULL";
         } else {
             if (!isset($fields[$name]["Value"])) {
                 return $this->SetError("Replace", "it was not specified a value for the {$name} field");
             }
             switch (isset($fields[$name]["Type"]) ? $fields[$name]["Type"] : "text") {
                 case "text":
                     $value = $this->GetTextFieldValue($fields[$name]["Value"]);
                     break;
                 case "boolean":
                     $value = $this->GetBooleanFieldValue($fields[$name]["Value"]);
                     break;
                 case "integer":
                     $value = strval($fields[$name]["Value"]);
                     break;
                 case "decimal":
                     $value = $this->GetDecimalFieldValue($fields[$name]["Value"]);
                     break;
                 case "float":
                     $value = $this->GetFloatFieldValue($fields[$name]["Value"]);
                     break;
                 case "date":
                     $value = $this->GetDateFieldValue($fields[$name]["Value"]);
                     break;
                 case "time":
                     $value = $this->GetTimeFieldValue($fields[$name]["Value"]);
                     break;
                 case "timestamp":
                     $value = $this->GetTimestampFieldValue($fields[$name]["Value"]);
                     break;
                 default:
                     return $this->SetError("Replace", "it was not specified a supported type for the {$name} field");
             }
         }
         $values .= $value;
         if (isset($fields[$name]["Key"]) && $fields[$name]["Key"]) {
             if ($value == "NULL") {
                 return $this->SetError("Replace", "key values may not be NULL");
             }
             $keys++;
         }
     }
     if ($keys == 0) {
         return $this->SetError("Replace", "it were not specified which fields are keys");
     }
     return $this->Query("REPLACE INTO {$table} ({$query}) VALUES({$values})");
 }
示例#30
0
 function FetchResultArray($result, &$array, $row)
 {
     $result_value = intval($result);
     if (!$this->FetchRow($result, $row) || !isset($this->columns[$result_value]) && !$this->GetColumnNames($result)) {
         return 0;
     }
     for ($array = array(), Reset($this->results[$result_value][$row]); $field = Key($this->results[$result_value][$row]); Next($this->results[$result_value][$row])) {
         $array[$this->columns[$result_value][$field]] = $this->results[$result_value][$row][$field];
     }
     $this->highest_fetched_row[$result_value] = max($this->highest_fetched_row[$result_value], $row);
     return $this->ConvertResultRow($result, $array);
 }