Advertisement
GOODPower

Untitled

May 20th, 2015
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.44 KB | None | 0 0
  1. <?class CSoftEffectPDF {
  2. function sendPDF($ID, $arFields) {
  3. global $USER;
  4.  
  5. $module_id = "softeffect.pdf";
  6. $person = explode(",", COption::GetOptionString($module_id, "SE_TYPE_PERSON_IDS", ""));
  7. $pay = explode(",", COption::GetOptionString($module_id, "SE_PAY_SYSTEM_IDS", ""));
  8.  
  9. if (in_array($arFields["PERSON_TYPE_ID"], $person) && in_array($arFields["PAY_SYSTEM_ID"], $pay)) {
  10. require_once $_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/softeffect.pdf/classes/general/execute.php";
  11. }
  12. }
  13.  
  14. function sendEmail($ID, &$eventName, &$arFields) {
  15. global $USER;
  16. $arOrder = CSaleOrder::GetByID($arFields["ORDER_ID"]);
  17.  
  18. $module_id = "softeffect.pdf";
  19. $person = explode(",", COption::GetOptionString($module_id, "SE_TYPE_PERSON_IDS", ""));
  20. $pay = explode(",", COption::GetOptionString($module_id, "SE_PAY_SYSTEM_IDS", ""));
  21.  
  22. if ((in_array($arOrder["PERSON_TYPE_ID"], $person) && in_array($arOrder["PAY_SYSTEM_ID"], $pay))) {
  23. return FALSE;
  24. }
  25.  
  26. }
  27.  
  28. //custom function
  29. function __AdmSettingsSaveOptionModify($module_id, $arOption)
  30. {
  31. $module_id = "softeffect.pdf";
  32. if(!is_array($arOption))
  33. return false;
  34.  
  35. $arControllerOption = CControllerClient::GetInstalledOptions($module_id);
  36.  
  37. if(isset($arControllerOption[$arOption[0]]))
  38. return false;
  39.  
  40. $name = $arOption[0];
  41. $val = $_REQUEST[$name];
  42.  
  43. if(array_key_exists(4, $arOption) && $arOption[4] == 'Y')
  44. {
  45. if($arOption[3][0] == 'checkbox')
  46. {
  47. $val = 'N';
  48. }
  49. else
  50. {
  51. return false;
  52. }
  53. }
  54.  
  55. if($arOption[3][0] == "checkbox" && $val != "Y")
  56. $val = "N";
  57. if($arOption[3][0] == "multiselectbox")
  58. $val = @implode(",", $val);
  59. if($arOption[3][0] == "multidoubletext") {
  60. $name = $arOption[3][0];
  61. $val = serialize($_REQUEST[$name]);
  62. //echo "<pre>"; print_r($arOption); echo "</pre>";die();
  63. }
  64.  
  65. COption::SetOptionString($module_id, $name, $val, $arOption[1]);
  66. }
  67.  
  68.  
  69. function __AdmListDrawRowModify($module_id, $Option)
  70. {
  71. $module_id = "softeffect.pdf";
  72. IncludeModuleLangFile(__FILE__);
  73. $arControllerOption = CControllerClient::GetInstalledOptions($module_id);
  74. $val = COption::GetOptionString($module_id, $Option[0], $Option[2]);
  75. $type = $Option[3];
  76. $Option[0] = $Option[0];
  77. $disabled = array_key_exists(4, $Option) && $Option[4] == 'Y' ? ' disabled' : '';
  78. $sup_text = array_key_exists(5, $Option) ? $Option[5] : '';
  79. if($type[0]=="multidoubletext") {
  80. $valText = COption::GetOptionString($module_id, $Option[0], $Option[2]);
  81. if($valText!=='') {
  82. $res.="<select name='templateLink'><option value='1'>".GetMessage("SELECT_TEMPLATE_S")."</option><option value='0'>".GetMessage("SELECT_TEMPLATE")."</option>";
  83. $arValue = unserialize($valText);
  84. $i=0;
  85. foreach($arValue as $arNameValueKey=>$arNameValue) {
  86. foreach($arNameValue as $arVal) {
  87. if($arNameValueKey=='Name' && ($arVal || $arValue[Value][$i])) {
  88. $res.="<option value='".htmlspecialchars($arValue[Value][$i])."|".$arValue[Album][$i]."|".$arValue[NameFile][$i]."'>".htmlspecialchars($arVal)."</option>";
  89. }
  90. $i++;
  91. }
  92. }
  93. $res.="</select>";
  94. return $res;
  95. }
  96. }
  97. }
  98.  
  99.  
  100. function __AdmSettingsDrawRowModify($module_id, $Option)
  101. {
  102. $module_id = "softeffect.pdf";
  103. IncludeModuleLangFile(__FILE__);
  104. $arControllerOption = CControllerClient::GetInstalledOptions($module_id);
  105. if(!is_array($Option)): ?>
  106. <tr class="heading">
  107. <td valign="top" colspan="2" align="center"><b><?=$Option?></b></td>
  108. </tr>
  109. <? else:
  110. $val = COption::GetOptionString($module_id, $Option[0], $Option[2]);
  111. $type = $Option[3];
  112. $Option[0] = $Option[0];
  113. $disabled = array_key_exists(4, $Option) && $Option[4] == 'Y' ? ' disabled' : '';
  114. $sup_text = array_key_exists(5, $Option) ? $Option[5] : '';
  115. ?>
  116. <tr>
  117. <td valign="top" width="60%"><?
  118. if($type[0]=="checkbox")
  119. echo "<label for='".htmlspecialchars($Option[0])."'>".$Option[1]."</label>";
  120. else
  121. echo $Option[1];
  122. if (strlen($sup_text) > 0)
  123. {
  124. ?><span class="required"><sup><?=$sup_text?></sup></span><?
  125. }
  126. ?></td>
  127. <td valign="middle" width="40%"><?
  128. if($type[0]=="checkbox"):
  129. ?><input type="checkbox" <?if(isset($arControllerOption[$Option[0]]))echo ' disabled title="'.GetMessage("MAIN_ADMIN_SET_CONTROLLER_ALT").'"';?> id="<?echo htmlspecialchars($Option[0])?>" name="<?echo htmlspecialchars($Option[0])?>" value="Y"<?if($val=="Y")echo" checked";?><?=$disabled?>><?
  130. elseif($type[0]=="text"):
  131. ?><input type="text" <?if(isset($arControllerOption[$Option[0]]))echo ' disabled title="'.GetMessage("MAIN_ADMIN_SET_CONTROLLER_ALT").'"';?> size="<?echo $type[1]?>" maxlength="255" value="<?echo htmlspecialchars($val)?>" name="<?echo htmlspecialchars($Option[0])?>"<?=$disabled?>><?
  132. elseif($type[0]=="selectbox"):
  133. $arr = $type[1];
  134. $arr_keys = array_keys($arr);
  135. ?><select name="<?echo htmlspecialchars($Option[0])?>" <?if(isset($arControllerOption[$Option[0]]))echo ' disabled title="'.GetMessage("MAIN_ADMIN_SET_CONTROLLER_ALT").'"';?> <?=$disabled?>><?
  136. for($j=0; $j<count($arr_keys); $j++):
  137. ?><option value="<?echo $arr_keys[$j]?>"<?if($val==$arr_keys[$j])echo" selected"?>><?echo htmlspecialchars($arr[$arr_keys[$j]])?></option><?
  138. endfor;
  139. ?></select><?
  140. elseif($type[0]=="multiselectbox"):
  141. $arr = $type[1];
  142. $arr_keys = array_keys($arr);
  143. $arr_val = explode(",",$val);
  144. ?><select size="5" <?if(isset($arControllerOption[$Option[0]]))echo ' disabled title="'.GetMessage("MAIN_ADMIN_SET_CONTROLLER_ALT").'"';?> multiple name="<?echo htmlspecialchars($Option[0])?>[]"<?=$disabled?>><?
  145. for($j=0; $j<count($arr_keys); $j++):
  146. ?><option value="<?echo $arr_keys[$j]?>"<?if(in_array($arr_keys[$j],$arr_val)) echo " selected"?>><?echo htmlspecialchars($arr[$arr_keys[$j]])?></option><?
  147. endfor;
  148. ?></select><?
  149. elseif($type[0]=="textarea"):
  150. ?><textarea <?if(isset($arControllerOption[$Option[0]]))echo ' disabled title="'.GetMessage("MAIN_ADMIN_SET_CONTROLLER_ALT").'"';?> rows="<?echo $type[1]?>" cols="<?echo $type[2]?>" name="<?echo htmlspecialchars($Option[0])?>"<?=$disabled?>><?echo htmlspecialchars($val)?></textarea><?
  151. elseif($type[0]=="multidoubletext"):
  152. ?>
  153. <div id="template">
  154. <table width="100%" cellpadding="3" cellspacing="0">
  155. <colgroup>
  156. <col width="25%" />
  157. <col width="25%" />
  158. <col width="25%" />
  159. <col width="25%" />
  160. </colgroup>
  161. <tbody id="template_table">
  162. <tr>
  163. <td><?=GetMessage("SE_MULTIDOUBLE_NAME")?></td>
  164. <td><?=GetMessage("SE_MULTIDOUBLE_VALUE")?></td>
  165. <td><?=GetMessage("SE_MULTIDOUBLE_NAMEFILE")?></td>
  166. <td><?=GetMessage("SE_MULTIDOUBLE_SCALE")?></td>
  167. </tr>
  168. <?
  169. $valText = COption::GetOptionString($module_id, $Option[0], $Option[2]);
  170. $arValue = unserialize($valText);
  171. if(
  172. isset($arValue['Name'][0]) && $arValue['Name'][0]!=='' ||
  173. isset($arValue['Value'][0]) && $arValue['Value'][0]!=='' ||
  174. isset($arValue['NameFile'][0]) && $arValue['NameFile'][0]!=='' ||
  175. isset($arValue['Album'][0]) && $arValue['Album'][0]!==''
  176. ) {
  177. $i=0;
  178. foreach($arValue as $arNameValueKey=>$arNameValue) {
  179. foreach($arNameValue as $arVal) {
  180. if($arNameValueKey=='Name' && ($arVal || $arValue['Value'][$i])) { ?>
  181. <tr class="tr_border">
  182. <td><input type="text" size="20" maxlength="255" value="<?=htmlspecialchars($arVal)?>" name="multidoubletext[<?=$arNameValueKey?>][]"<?=$disabled?> /></td>
  183. <td><input type="text" size="20" maxlength="255" value="<?=htmlspecialchars($arValue['Value'][$i])?>" name="multidoubletext[Value][]"<?=$disabled?> /></td>
  184. <td><input type="text" size="20" maxlength="255" value="<?=htmlspecialchars($arValue[NameFile][$i])?>" name="multidoubletext[NameFile][]"<?=$disabled?> /></td>
  185. <td><input type="checkbox" name="multidoubletext[Album][<?=$i?>]" <?=($arValue['Album'][$i] ? "checked='checked'" : NULL)?> id="Album<?=$i?>" /> <label for="Album<?=$i?>"><?=GetMessage("ALBUM_ORIENTATION")?></label></td>
  186. </tr>
  187. <? }
  188. $i++;
  189. }
  190. }
  191. } else { ?>
  192. <tr class="tr_border">
  193. <td><input type="text" size="20" maxlength="255" value="<?=htmlspecialchars($arVal)?>" name="multidoubletext[Name][]"<?=$disabled?> /></td>
  194. <td><input type="text" size="20" maxlength="255" value="<?=htmlspecialchars($arValue['Value'][$i])?>" name="multidoubletext[Value][]"<?=$disabled?> /></td>
  195. <td><input type="text" size="20" maxlength="255" value="<?=htmlspecialchars($arValue[NameFile][$i])?>" name="multidoubletext[NameFile][]"<?=$disabled?> /></td>
  196. <td><input type="checkbox" name="multidoubletext[Album][<?=$i?>]" <?=($arValue['Album'][$i] ? "checked='checked'" : NULL)?> id="Album<?=$i?>" /> <label for="Album<?=$i?>"><?=GetMessage("ALBUM_ORIENTATION")?></label></td>
  197. </tr>
  198. <? } ?>
  199. </tbody>
  200. </table>
  201. </div>
  202. <a href='javascript:void(0);' id='createTemplate' style="clear:both;display:block; float:left;" /><?=GetMessage("ADD_TEMPLATE");?></a>
  203. <script type="text/javascript">
  204. i = 0;
  205. window.onload = function() {
  206. var link = document.getElementById("createTemplate");
  207. link.onclick = function () {
  208. i = i+1;
  209. var divT = document.getElementById('template_table');
  210. html = '<tr class="tr_border"><td><input type="text" size="20" maxlength="255" value="" name="<?=htmlspecialchars($type[0])?>[Name][]"<?=$disabled?> /></td><td><input type="text" size="20" maxlength="255" value="" name="<?=htmlspecialchars($type[0])?>[Value][]"<?=$disabled?> /></td><td><input type="text" size="20" maxlength="255" value="" name="<?=htmlspecialchars($type[0])?>[NameFile][]"<?=$disabled?> /></td><td><input type="checkbox" name="multidoubletext[Album][]" id="Album'+i+'" />&nbsp;<label for="Album'+i+'"><?=GetMessage("ALBUM_ORIENTATION")?></label></td></tr>';
  211. divT.innerHTML = divT.innerHTML + html;
  212. }
  213. }
  214. </script>
  215. <?
  216. endif;
  217. ?></td>
  218. </tr>
  219. <?
  220. endif;
  221. }
  222.  
  223.  
  224. function ShowParamsHTMLByArray($arParams) {
  225. foreach($arParams as $Option) {
  226. CSoftEffectPDF::__AdmSettingsDrawRowModify("softeffect.pdf", $Option);
  227. }
  228. }
  229.  
  230. function MyOnAdminListDisplay(&$list) {
  231. IncludeModuleLangFile(__FILE__);
  232. if ($list->table_id == "tbl_sale_order") {
  233. $list->arActions["st_template"] = GetMessage("PDF_SEND_TEMPLATE");
  234.  
  235. $module_id = "softeffect.pdf";
  236.  
  237. CModule::AddAutoloadClasses(
  238. $module_id,
  239. array(
  240. 'CSoftEffectPDF' => 'classes/general/CSoftEffectPDF.php',
  241. )
  242. );
  243.  
  244. $Option = COption::GetOptionString($module_id, "multidoubletext", "");
  245. $Option = CSoftEffectPDF::__AdmListDrawRowModify($module_id,Array("multidoubletext", "","",Array('multidoubletext',$Option)));
  246. $strIBlocksCp = "<div id='template_send' style='display:none;'>".$Option."</div><input type='hidden' name='table_id' value='tbl_sale_order' />";
  247. $list->arActions['st_template_chooser'] = array('type' => 'html', 'value' => $strIBlocksCp);
  248. $list->arActionsParams['select_onchange'] .= "BX('template_send').style.display = (this.value == 'st_template'? 'block':'none');";
  249. }
  250. }
  251.  
  252. function OnBeforePrologHandler() {
  253. global $APPLICATION;
  254. global $DB;
  255. global $USER;
  256. if ($_REQUEST['action'] == "st_template" && $_REQUEST['templateLink'] && $_REQUEST["table_id"]=="tbl_sale_order") {
  257. if (!empty($_REQUEST['ID'])) {
  258. require_once $_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/softeffect.pdf/classes/general/mail_attach.php";
  259. CModule::IncludeModule("sale");
  260. CModule::IncludeModule("main");
  261. $url='http://saas.softcliens.tmweb.ru/pdf/curl.php';
  262. foreach ($_REQUEST['ID'] as $arID) {
  263. $ar_sales = CSaleOrder::GetByID($arID);
  264.  
  265. $rsSites = CSite::GetByID($ar_sales["LID"]);
  266. $arSite = $rsSites->Fetch();
  267.  
  268. $module = CModule::IncludeModuleEx('softeffect.pdf');
  269. $namePDF = 'invoice_'.(int)$arID.'.pdf';
  270. if ($module==2) {
  271. $namePDF = 'invoice_'.(int)$order_id.'_softeffect.ru_DEMO_MODE.pdf';
  272. } elseif ($module==3) {
  273. $namePDF = 'invoice_'.(int)$order_id.'_DEMO_IS_OVER_buy_module_in_softeffect.ru.pdf';
  274. }
  275.  
  276. $filePath = $_SERVER['DOCUMENT_ROOT'].'/upload/softeffect.pdf/'.$namePDF;
  277. if(is_array($ar_sales)) {
  278. $ar_user = CUser::GetByID($ar_sales["USER_ID"]);
  279. $ar_user = $ar_user->Fetch();
  280. $userMail = $ar_user["EMAIL"];
  281. $html = "";
  282.  
  283. $strOrderList = "";
  284. $dbBasketItems = CSaleBasket::GetList(
  285. array("NAME" => "ASC"),
  286. array("ORDER_ID" => $arID),
  287. false,
  288. false,
  289. array("ID", "NAME", "QUANTITY")
  290. );
  291.  
  292. while ($arBasketItems = $dbBasketItems->Fetch()) {
  293. $strOrderList .= $arBasketItems["NAME"]." - ".$arBasketItems["QUANTITY"]." ".GetMessage("SOA_SHT");
  294. $strOrderList .= "\n";
  295. }
  296.  
  297. $arFieldsMail = Array(
  298. "ORDER_ID" => $arID,
  299. "ORDER_DATE" => Date($DB->DateFormatToPHP(CLang::GetDateFormat("SHORT", SITE_ID))),
  300. "ORDER_USER" => $ar_user["NAME"]." ".$ar_user["LAST_NAME"],
  301. "PRICE" => SaleFormatCurrency($ar_sales["PRICE"], $ar_sales["CURRENCY"]),
  302. "BCC" => COption::GetOptionString("sale", "order_email", "order@".$SERVER_NAME),
  303. "EMAIL" => $userMail,
  304. "ORDER_LIST" => $strOrderList,
  305. "SALE_EMAIL" => COption::GetOptionString("sale", "order_email", "order@".$SERVER_NAME)
  306. );
  307. $module_id = "softeffect.pdf";
  308. $strPay = COption::GetOptionString($module_id, "SE_PAY_SYSTEM_IDS", "");
  309.  
  310. $arPay = explode(",",$strPay);
  311. $paySystem = 0;
  312. foreach($arPay as $payVal){
  313. if($payVal==$ar_sales["PAY_SYSTEM_ID"]) { $paySystem = 1; }
  314. }
  315.  
  316. //esli schet
  317. if($_REQUEST["templateLink"] == 1) {
  318. $album_orientation = COption::GetOptionString($module_id, "ALBUM_ORIENTATION", "");
  319. $_REQUEST["ORDER_ID"] = $arID;
  320. $_REQUEST["USER_ID"] = $ar_sales["USER_ID"];
  321. define('ETC_EXECUTE_COMPONENT', true);
  322. if($paySystem) {
  323. ob_start();
  324. $APPLICATION->IncludeComponent(
  325. "softeffect:sale.order.payment",
  326. "",
  327. array()
  328. );
  329. $html = ob_get_contents();
  330. ob_end_clean();
  331. var_dump($html);
  332. if ($module==3) {
  333. $html = '<html><body><div style="color: red; text-align: justify;">DEMO IS OVER! DEMO IS OVER! DEMO IS OVER!</div></body></html>';
  334. }
  335. $postfields = array("html" => str_replace(array("src='","src=\"", "href='/", "href=\"/"),
  336. array("src='http://".$_SERVER["SERVER_NAME"],"src=\"http://".$_SERVER["SERVER_NAME"], "href='http://".$_SERVER["SERVER_NAME"]."/","href=\"http://".$_SERVER["SERVER_NAME"]."/"),$html), "charset" => $arSite["CHARSET"],"landscape" => $album_orientation);
  337. $ch = curl_init();
  338. curl_setopt($ch, CURLOPT_URL,$url);
  339. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  340. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  341. curl_setopt($ch, CURLOPT_POST, 1);
  342. curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
  343. $result = curl_exec($ch);
  344. curl_close($ch);
  345. file_put_contents($filePath, $result);
  346. chmod($filePath, 0777);
  347. SendAttache("SALE_NEW_ORDER", $ar_sales["LID"], $arFieldsMail, $filePath);
  348. } else {
  349. CEvent::Send("SALE_NEW_ORDER", $ar_sales["LID"], $arFieldsMail);
  350. }
  351. } else {
  352.  
  353. $arParam = explode("|",$_REQUEST['templateLink']);
  354. if($arParam[2]){
  355. $namePDF = $arParam[2].'_'.(int)$arID.'.pdf';
  356. $filePath = $_SERVER['DOCUMENT_ROOT'].'/upload/softeffect.pdf/'.$namePDF;
  357. }
  358. if (file_exists($_SERVER["DOCUMENT_ROOT"].$arParam[0])) {
  359. $htm = curl_init();
  360. $postfieldsHtml = array("ORDER_ID"=>$arID);
  361. curl_setopt($htm, CURLOPT_URL,$_SERVER["SERVER_NAME"].$arParam[0]);
  362. curl_setopt($htm, CURLOPT_SSL_VERIFYPEER, 0);
  363. curl_setopt($htm, CURLOPT_RETURNTRANSFER,1);
  364. curl_setopt($htm, CURLOPT_POST, 1);
  365. curl_setopt($htm, CURLOPT_POSTFIELDS, $postfieldsHtml);
  366. $html = curl_exec($htm);
  367. curl_close($htm);
  368.  
  369. if ($module==3) {
  370. $html = '<html><body><div style="color: red; text-align: justify;">DEMO IS OVER! DEMO IS OVER! DEMO IS OVER!</div></body></html>';
  371. }
  372. $postfields = array("html" => str_replace(array("src='","src=\"", "href='/", "href=\"/"),
  373. array("src='http://".$_SERVER["SERVER_NAME"],"src=\"http://".$_SERVER["SERVER_NAME"],
  374. "href='http://".$_SERVER["SERVER_NAME"]."/","href=\"http://".$_SERVER["SERVER_NAME"]."/"),$html),
  375. "charset" => $arSite["CHARSET"],
  376. "landscape" => $arParam[1]
  377. );
  378.  
  379. $ch = curl_init();
  380. curl_setopt($ch, CURLOPT_URL,$url);
  381. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  382. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  383. curl_setopt($ch, CURLOPT_POST, 1);
  384. curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
  385. $result = curl_exec($ch);
  386. curl_close($ch);
  387. file_put_contents($filePath, $result);
  388. chmod($filePath, 0777);
  389. SendAttache("SEND_FILE_USER", $ar_sales["LID"], $arFieldsMail, $filePath);
  390. }
  391. }
  392. @unlink($filePath);
  393. }
  394. }
  395. }
  396. }
  397. }
  398. }?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement