case "my/offert.doc":
$partnerId = isset($_SESSION['auth']['info']['partnerId']) ? $_SESSION['auth']['info']['partnerId'] : false;
if ($partnerId === false) {
throw new Exception("Permission denied", 403);
}
$partnerInfo = $this->modulesManager->run("users", "@partner_info", array("partnerId" => $partnerId));
$operatorInfo = $operatorInfo = $this->modulesManager->run("users", "@get_operator_info", array("id" => $partnerInfo["operatorId"], "skipErrors" => true));
//echo "Operator info development dump: <pre>";var_dump($operatorInfo); exit();
$partnerType = $partnerInfo['partnerType'];
switch ($partnerType) {
case "company":
if (array_search("ИПБЮЛ", array($partnerInfo['orgUrType']))) {
$fname = "company_IPBUL.rtf";
} else {
$fname = "compnay.rtf";
}
break;
case "independent":
$fname = "independent_IPBUL.rtf"; break;
break;
default:
throw new Exception("Can't detect partner type", 404);
}
//echo "Ориг: \'cf\'f0\'e8\'e2\'e5\'f2 \'ab\'ce\'ce\'ce \'c8\'ed\'ed\'ee\'e2\'e0\'bb<br>".strint2rft(iconv("utf-8", "cp1251", "Привет ООО"));
error_reporting(0);
header("Content-type: text/rtf");
//exit();
$contact_rtf = file_get_contents("uploads/docs/contracts/rtf/{$fname}");
$replacement = array(
"administratorOrganisationForm" => $operatorInfo['administratorOrganisationForm'], // ООО
"administratorOrgTitle" => $operatorInfo['administratorOrgTitle'], // Рога и копыта
"administratorPhone" => $operatorInfo['administratorPhone'],
"administratorInn" => $operatorInfo['administratorInn'],
"administratorEmail" => $operatorInfo['administratorEmail'],
"administratorOgrnCode" => $operatorInfo['administratorOgrnCode'],
"administratorKppCode" => $operatorInfo['administratorKppCode'],
"administratorDocAddress" => $operatorInfo['administratorDocAddress'],
"administratorFactAddress" => $operatorInfo['administratorFactAddress'],
"administratorBankTitle" => $operatorInfo['administratorBankTitle'],
"administratorBankBikCode" => $operatorInfo['administratorBankBikCode'],
"administratorBankAccountCode" => $operatorInfo['administratorBankAccountCode'], // кор счет
"administratorAccountCode" => $operatorInfo['administratorAccountCode'], // р/счет
"administratorBossName" => $operatorInfo['administratorBossName'],
"administratorUrOsnovanie" => $operatorInfo['administratorUrOsnovanie'],
"administratorBossSignature" => $operatorInfo['administratorBossSignature'],
"administratorBossWho" => $operatorInfo['administratorBossWho'],
"administratorBossRod" => $operatorInfo['administratorBossRod'],
"login" => $partnerInfo['login'],
"dateD" => date("d", strtotime($partnerInfo['registratedTime'])),
"dateM" => date("m", strtotime($partnerInfo['registratedTime'])),
"dateY" => date("Y", strtotime($partnerInfo['registratedTime'])),
"urtype" => $partnerInfo['orgUrType'],
"urname" => $partnerInfo['orgUrName'],
"brend" => $partnerInfo['title'],
"bosswhodoc" => $partnerInfo['bossWhoDoc'],
"bossdoc" => $partnerInfo['bossWhyDoc'],
"urtype" => $partnerInfo['orgUrType'],
"urname" => $partnerInfo['orgUrName'],
"uraddress" => $partnerInfo['urAddress'],
"postaddress" => $partnerInfo['postAddress'],
"inn" => $partnerInfo['inn'],
"kpp" => "", //$partnerInfo[''],
"okpo" => "", //$partnerInfo[''],
"rschet" => $partnerInfo['rSchet'],
"bank" => $partnerInfo['bankTitle'],
"bik" => $partnerInfo['bik'],
"kschet" => $partnerInfo['korSchet'],
"telephone" => ($partnerInfo['partnerType'] == "company" ? $partnerInfo['phone'] : $partnerInfo['userContactPhone']),
"fax" => $partnerInfo['fax'],
"email" => ($partnerInfo['partnerType'] == "company" ? $partnerInfo['email'] : $partnerInfo['userEmail']),
"bosswho" => $partnerInfo['bossWho'],
"boss_signature" => (
$partnerInfo['partnerType'] == "company" ?
"{$partnerInfo['bossLastName']} ".mb_substr($partnerInfo['bossFirstName'], 0,1,"utf-8").". ".mb_substr($partnerInfo['bossMiddleName'],0,1,"utf-8")."."
:
"{$partnerInfo['userLastName']} ".mb_substr($partnerInfo['userFirstName'], 0,1,"utf-8").". ".mb_substr($partnerInfo['userMiddleName'],0,1,"utf-8")."."
),
"boss" => "{$partnerInfo['bossLastName']} {$partnerInfo['bossFirstName']} {$partnerInfo['bossMiddleName']}",
"lastname" => $partnerInfo['userLastName'],
"firstname" => $partnerInfo['userFirstName'],
"middlename" => $partnerInfo['userMiddleName'],
"ogrn" => $partnerInfo['ogrn'],
);
foreach ($replacement as $key => $value) {
$contact_rtf = str_replace($key, strint2rft(iconv("utf-8", "cp1251", $value)), $contact_rtf);
}
echo $contact_rtf;
exit();
throw new Exception("OK", 200);
//...
function strint2rft($string) {
//echo $string;
return preg_replace("/([А-Яа-яёЁтТ]{1,1})/ei", "\"\'\".dechex(ord(\"\\1\"))", $string);
}