api.templatize.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. <?php
  2. /**
  3. * Returns all data from multinet hosts
  4. *
  5. * @return array
  6. */
  7. function zb_MultinetGetAllData() {
  8. $query = "SELECT * from `nethosts`";
  9. $result = array();
  10. $allhosts = simple_queryall($query);
  11. if (!empty($allhosts)) {
  12. foreach ($allhosts as $io => $eachhost) {
  13. $result[$eachhost['ip']]['ip'] = $eachhost['ip'];
  14. $result[$eachhost['ip']]['mac'] = $eachhost['mac'];
  15. $result[$eachhost['ip']]['netid'] = $eachhost['netid'];
  16. $result[$eachhost['ip']]['id'] = $eachhost['id'];
  17. }
  18. }
  19. return ($result);
  20. }
  21. /**
  22. * Returns NAS params by netid
  23. *
  24. * @param int $netid - multinet network ID
  25. * @param array $allnasdata - array of all NAS data
  26. *
  27. * @return array
  28. */
  29. function zb_NasGetParams($netid, $allnasdata) {
  30. $netid = vf($netid, 3);
  31. $result = array();
  32. if (!empty($allnasdata)) {
  33. foreach ($allnasdata as $io => $eachnas) {
  34. if ($eachnas['netid'] == $netid) {
  35. $result = $eachnas;
  36. }
  37. }
  38. }
  39. return ($result);
  40. }
  41. /**
  42. * Return all CF content by login
  43. *
  44. * @param string $login - existing user login
  45. * @param array $allcfdata - all CF data array
  46. * @return array
  47. */
  48. function zb_cfGetContent($login, $allcfdata) {
  49. $login = mysql_real_escape_string($login);
  50. $result = array();
  51. if (!empty($allcfdata)) {
  52. foreach ($allcfdata as $io => $eachcf) {
  53. if ($eachcf['login'] == $login) {
  54. $result[$eachcf['typeid']] = $eachcf['content'];
  55. }
  56. }
  57. }
  58. return ($result);
  59. }
  60. /**
  61. * Fetch all Payment IDs from database as virtualid=>login
  62. *
  63. * @return array
  64. */
  65. function zb_TemplateGetAllOPCustomers() {
  66. global $ubillingConfig;
  67. $result = array();
  68. if ($ubillingConfig->getAlterParam('OPENPAYZ_SUPPORT')) {
  69. $query = "SELECT * from `op_customers`";
  70. $all = simple_queryall($query);
  71. if (!empty($all)) {
  72. foreach ($all as $io => $each) {
  73. $result[$each['realid']] = $each['virtualid'];
  74. }
  75. }
  76. }
  77. return ($result);
  78. }
  79. /**
  80. * Returns all data about current userbase
  81. * which used for templatizing functions
  82. *
  83. * @return array
  84. */
  85. function zb_TemplateGetAllUserData() {
  86. $altcfg = rcms_parse_ini_file(CONFIG_PATH . "alter.ini");
  87. $userdata = array();
  88. $alluserdata = zb_UserGetAllStargazerData();
  89. $tariffspeeds = zb_TariffGetAllSpeeds();
  90. $tariffprices = zb_TariffGetPricesAll();
  91. $multinetdata = zb_MultinetGetAllData();
  92. $allcontracts = zb_UserGetAllLoginContracts();
  93. $allrealnames = zb_UserGetAllRealnames();
  94. $alladdress = zb_AddressGetFulladdresslist();
  95. $allemails = zb_UserGetAllEmails();
  96. $allnasdata = zb_NasGetAllData();
  97. $cf = new CustomFields();
  98. $allcfdata = $cf->getAllFieldsData();
  99. $allpdata = zb_UserPassportDataGetAll();
  100. $phoneDataRaw = zb_UserGetAllPhoneData();
  101. $allMobileData = array();
  102. $allPhoneData = array();
  103. if (!empty($phoneDataRaw)) {
  104. foreach ($phoneDataRaw as $io => $each) {
  105. $allMobileData[$io] = $each['mobile'];
  106. $allPhoneData[$io] = $each['phone'];
  107. }
  108. }
  109. if ($altcfg['OPENPAYZ_SUPPORT']) {
  110. if ($altcfg['OPENPAYZ_REALID']) {
  111. $allopcustomers = zb_TemplateGetAllOPCustomers();
  112. }
  113. }
  114. if (!empty($alluserdata)) {
  115. foreach ($alluserdata as $io => $eachuser) {
  116. $userdata[$eachuser['login']]['login'] = $eachuser['login'];
  117. $userdata[$eachuser['login']]['password'] = $eachuser['Password'];
  118. $userdata[$eachuser['login']]['userhash'] = crc16($eachuser['login']);
  119. $userdata[$eachuser['login']]['tariff'] = $eachuser['Tariff'];
  120. @$userdata[$eachuser['login']]['tariffprice'] = $tariffprices[$eachuser['Tariff']];
  121. $userdata[$eachuser['login']]['cash'] = $eachuser['Cash'];
  122. $userdata[$eachuser['login']]['credit'] = $eachuser['Credit'];
  123. $userdata[$eachuser['login']]['down'] = $eachuser['Down'];
  124. $userdata[$eachuser['login']]['passive'] = $eachuser['Passive'];
  125. $userdata[$eachuser['login']]['ao'] = $eachuser['AlwaysOnline'];
  126. @$userdata[$eachuser['login']]['contract'] = $allcontracts[$eachuser['login']];
  127. @$userdata[$eachuser['login']]['realname'] = $allrealnames[$eachuser['login']];
  128. @$userdata[$eachuser['login']]['address'] = $alladdress[$eachuser['login']];
  129. @$userdata[$eachuser['login']]['email'] = $allemails[$eachuser['login']];
  130. @$userdata[$eachuser['login']]['mobile'] = $allMobileData[$eachuser['login']];
  131. @$userdata[$eachuser['login']]['phone'] = $allPhoneData[$eachuser['login']];
  132. //openpayz payment ID
  133. if ($altcfg['OPENPAYZ_REALID']) {
  134. @$userdata[$eachuser['login']]['payid'] = $allopcustomers[$eachuser['login']];
  135. } else {
  136. @$userdata[$eachuser['login']]['payid'] = ip2int($eachuser['IP']);
  137. }
  138. //traffic params
  139. $userdata[$eachuser['login']]['traffic'] = $eachuser['D0'] + $eachuser['U0'];
  140. $userdata[$eachuser['login']]['trafficdown'] = $eachuser['D0'];
  141. $userdata[$eachuser['login']]['trafficup'] = $eachuser['U0'];
  142. //net params
  143. $userdata[$eachuser['login']]['ip'] = $eachuser['IP'];
  144. @$userdata[$eachuser['login']]['mac'] = $multinetdata[$eachuser['IP']]['mac'];
  145. @$userdata[$eachuser['login']]['netid'] = $multinetdata[$eachuser['IP']]['netid'];
  146. @$userdata[$eachuser['login']]['hostid'] = $multinetdata[$eachuser['IP']]['id'];
  147. //nas data
  148. @$usernas = zb_NasGetParams($multinetdata[$eachuser['IP']]['netid'], $allnasdata);
  149. @$userdata[$eachuser['login']]['nasid'] = $usernas['id'];
  150. @$userdata[$eachuser['login']]['nasip'] = $usernas['nasip'];
  151. @$userdata[$eachuser['login']]['nasname'] = $usernas['nasname'];
  152. @$userdata[$eachuser['login']]['nastype'] = $usernas['nastype'];
  153. if (isset($tariffspeeds[$eachuser['Tariff']])) {
  154. $userdata[$eachuser['login']]['speeddown'] = $tariffspeeds[$eachuser['Tariff']]['speeddown'];
  155. $userdata[$eachuser['login']]['speedup'] = $tariffspeeds[$eachuser['Tariff']]['speedup'];
  156. } else {
  157. //if no tariff speed defined zero speed by default
  158. $userdata[$eachuser['login']]['speeddown'] = 0;
  159. $userdata[$eachuser['login']]['speedup'] = 0;
  160. }
  161. //CF data
  162. $usercfdata = zb_cfGetContent($eachuser['login'], $allcfdata);
  163. if (!empty($usercfdata)) {
  164. foreach ($usercfdata as $cd => $eachcf) {
  165. $userdata[$eachuser['login']]['cf'][$cd] = $eachcf;
  166. }
  167. }
  168. //passport data
  169. @$userdata[$eachuser['login']]['birthdate'] = $allpdata[$eachuser['login']]['birthdate'];
  170. @$userdata[$eachuser['login']]['passportnum'] = $allpdata[$eachuser['login']]['passportnum'];
  171. @$userdata[$eachuser['login']]['passportdate'] = $allpdata[$eachuser['login']]['passportdate'];
  172. @$userdata[$eachuser['login']]['passportwho'] = $allpdata[$eachuser['login']]['passportwho'];
  173. @$userdata[$eachuser['login']]['pcity'] = $allpdata[$eachuser['login']]['pcity'];
  174. @$userdata[$eachuser['login']]['pstreet'] = $allpdata[$eachuser['login']]['pstreet'];
  175. @$userdata[$eachuser['login']]['pbuild'] = $allpdata[$eachuser['login']]['pbuild'];
  176. @$userdata[$eachuser['login']]['papt'] = $allpdata[$eachuser['login']]['papt'];
  177. // {LACK} parameter support
  178. if (@empty($eachuser['TariffChange'])) {
  179. $userdata[$eachuser['login']]['moneylack'] = @$tariffprices[$eachuser['Tariff']] - $eachuser['Cash'];
  180. } else {
  181. $userdata[$eachuser['login']]['moneylack'] = @$tariffprices[$eachuser['TariffChange']] - $eachuser['Cash'];
  182. }
  183. }
  184. }
  185. return ($userdata);
  186. }
  187. /**
  188. * Replaces all known macro in template with current per-user values
  189. *
  190. * @param string $template raw template
  191. * @param array $alluserdata collected userdata
  192. * @return string
  193. */
  194. function zb_TemplateReplaceAll($template, $alluserdata) {
  195. $result = '';
  196. if (!empty($alluserdata)) {
  197. foreach ($alluserdata as $io => $each) {
  198. $result .= $template;
  199. //known macro
  200. $result = str_ireplace('{LOGIN}', $each['login'], $result);
  201. $result = str_ireplace('{PASSWORD}', $each['password'], $result);
  202. $result = str_ireplace('{USERHASH}', $each['userhash'], $result);
  203. $result = str_ireplace('{TARIFF}', $each['tariff'], $result);
  204. $result = str_ireplace('{TARIFFPRICE}', $each['tariffprice'], $result);
  205. $result = str_ireplace('{CASH}', $each['cash'], $result);
  206. $result = str_ireplace('{CREDIT}', $each['credit'], $result);
  207. $result = str_ireplace('{LACK}', $each['moneylack'], $result);
  208. $result = str_ireplace('{DOWN}', $each['down'], $result);
  209. $result = str_ireplace('{PASSIVE}', $each['passive'], $result);
  210. $result = str_ireplace('{AO}', $each['ao'], $result);
  211. $result = str_ireplace('{CONTRACT}', $each['contract'], $result);
  212. $result = str_ireplace('{REALNAME}', $each['realname'], $result);
  213. $result = str_ireplace('{ADDRESS}', $each['address'], $result);
  214. $result = str_ireplace('{EMAIL}', $each['email'], $result);
  215. $result = str_ireplace('{PAYID}', $each['payid'], $result);
  216. $result = str_ireplace('{TRAFFIC}', $each['traffic'], $result);
  217. $result = str_ireplace('{TRAFFICDOWN}', $each['trafficdown'], $result);
  218. $result = str_ireplace('{TRAFFICUP}', $each['trafficup'], $result);
  219. $result = str_ireplace('{IP}', $each['ip'], $result);
  220. $result = str_ireplace('{MAC}', $each['mac'], $result);
  221. $result = str_ireplace('{NETID}', $each['netid'], $result);
  222. $result = str_ireplace('{HOSTID}', $each['hostid'], $result);
  223. $result = str_ireplace('{NASID}', $each['nasid'], $result);
  224. $result = str_ireplace('{NASIP}', $each['nasip'], $result);
  225. $result = str_ireplace('{NASNAME}', $each['nasname'], $result);
  226. $result = str_ireplace('{NASTYPE}', $each['nastype'], $result);
  227. $result = str_ireplace('{SPEEDDOWN}', $each['speeddown'], $result);
  228. $result = str_ireplace('{SPEEDUP}', $each['speedup'], $result);
  229. $result = str_ireplace('{PBIRTH}', $each['birthdate'], $result);
  230. $result = str_ireplace('{PNUM}', $each['passportnum'], $result);
  231. $result = str_ireplace('{PDATE}', $each['passportdate'], $result);
  232. $result = str_ireplace('{PWHO}', $each['passportwho'], $result);
  233. $result = str_ireplace('{PCITY}', $each['pcity'], $result);
  234. $result = str_ireplace('{PSTREET}', $each['pstreet'], $result);
  235. $result = str_ireplace('{PBUILD}', $each['pbuild'], $result);
  236. $result = str_ireplace('{PAPT}', $each['papt'], $result);
  237. //custom fields extraction
  238. if (ispos($result, '{CFIELD:')) {
  239. $split = explode('{CFIELD:', $result);
  240. $cleanCf = explode('}', $split[1]);
  241. $cfid = vf($cleanCf[0], 3);
  242. $result = str_ireplace('{CFIELD:' . $cfid . '}', @$each['cf'][$cfid], $result);
  243. }
  244. //print macro
  245. $printsub = '<script language="javascript">
  246. window.print();
  247. </script>';
  248. $result = str_ireplace('{PRINTME}', $printsub, $result);
  249. }
  250. }
  251. return ($result);
  252. }
  253. /**
  254. * Replaces all known macro in template with per-user values for selected user
  255. *
  256. * @param string $login existing user login
  257. * @param string $template raw template
  258. * @param array $alluserdata collected userdata
  259. * @return string
  260. */
  261. function zb_TemplateReplace($login, $template, $alluserdata) {
  262. $result = '';
  263. if (!empty($alluserdata)) {
  264. $result .= $template;
  265. //known macro
  266. $result = str_ireplace('{LOGIN}', $alluserdata[$login]['login'], $result);
  267. $result = str_ireplace('{PASSWORD}', $alluserdata[$login]['password'], $result);
  268. $result = str_ireplace('{USERHASH}', $alluserdata[$login]['userhash'], $result);
  269. $result = str_ireplace('{TARIFF}', $alluserdata[$login]['tariff'], $result);
  270. $result = str_ireplace('{TARIFFPRICE}', $alluserdata[$login]['tariffprice'], $result);
  271. $result = str_ireplace('{CASH}', $alluserdata[$login]['cash'], $result);
  272. $result = str_ireplace('{ROUNDCASH}', round($alluserdata[$login]['cash'], 2), $result);
  273. $result = str_ireplace('{CURDATE}', curdate(), $result);
  274. $result = str_ireplace('{CREDIT}', $alluserdata[$login]['credit'], $result);
  275. $result = str_ireplace('{LACK}', $alluserdata[$login]['moneylack'], $result);
  276. $result = str_ireplace('{DOWN}', $alluserdata[$login]['down'], $result);
  277. $result = str_ireplace('{PASSIVE}', $alluserdata[$login]['passive'], $result);
  278. $result = str_ireplace('{AO}', $alluserdata[$login]['ao'], $result);
  279. $result = str_ireplace('{CONTRACT}', $alluserdata[$login]['contract'], $result);
  280. $result = str_ireplace('{REALNAME}', $alluserdata[$login]['realname'], $result);
  281. $result = str_ireplace('{ADDRESS}', $alluserdata[$login]['address'], $result);
  282. $result = str_ireplace('{EMAIL}', $alluserdata[$login]['email'], $result);
  283. $result = str_ireplace('{MOBILE}', $alluserdata[$login]['mobile'], $result);
  284. $result = str_ireplace('{PHONE}', $alluserdata[$login]['phone'], $result);
  285. $result = str_ireplace('{PAYID}', $alluserdata[$login]['payid'], $result);
  286. $result = str_ireplace('{TRAFFIC}', $alluserdata[$login]['traffic'], $result);
  287. $result = str_ireplace('{TRAFFICDOWN}', $alluserdata[$login]['trafficdown'], $result);
  288. $result = str_ireplace('{TRAFFICUP}', $alluserdata[$login]['trafficup'], $result);
  289. $result = str_ireplace('{IP}', $alluserdata[$login]['ip'], $result);
  290. $result = str_ireplace('{MAC}', $alluserdata[$login]['mac'], $result);
  291. $result = str_ireplace('{NETID}', $alluserdata[$login]['netid'], $result);
  292. $result = str_ireplace('{HOSTID}', $alluserdata[$login]['hostid'], $result);
  293. $result = str_ireplace('{NASID}', $alluserdata[$login]['nasid'], $result);
  294. $result = str_ireplace('{NASIP}', $alluserdata[$login]['nasip'], $result);
  295. $result = str_ireplace('{NASNAME}', $alluserdata[$login]['nasname'], $result);
  296. $result = str_ireplace('{NASTYPE}', $alluserdata[$login]['nastype'], $result);
  297. $result = str_ireplace('{SPEEDDOWN}', $alluserdata[$login]['speeddown'], $result);
  298. $result = str_ireplace('{SPEEDUP}', $alluserdata[$login]['speedup'], $result);
  299. $result = str_ireplace('{PBIRTH}', $alluserdata[$login]['birthdate'], $result);
  300. $result = str_ireplace('{PNUM}', $alluserdata[$login]['passportnum'], $result);
  301. $result = str_ireplace('{PDATE}', $alluserdata[$login]['passportdate'], $result);
  302. $result = str_ireplace('{PWHO}', $alluserdata[$login]['passportwho'], $result);
  303. $result = str_ireplace('{PCITY}', $alluserdata[$login]['pcity'], $result);
  304. $result = str_ireplace('{PSTREET}', $alluserdata[$login]['pstreet'], $result);
  305. $result = str_ireplace('{PBUILD}', $alluserdata[$login]['pbuild'], $result);
  306. $result = str_ireplace('{PAPT}', $alluserdata[$login]['papt'], $result);
  307. //custom fields extract
  308. if (ispos($result, '{CFIELD:')) {
  309. $split = explode('{CFIELD:', $result);
  310. $cleanCf = explode('}', $split[1]);
  311. $cfid = vf($cleanCf[0], 3);
  312. $result = str_ireplace('{CFIELD:' . $cfid . '}', @$alluserdata[$login]['cf'][$cfid], $result);
  313. }
  314. //print macro
  315. $printsub = '<script language="javascript">
  316. window.print();
  317. </script>';
  318. $result = str_ireplace('{PRINTME}', $printsub, $result);
  319. }
  320. return ($result);
  321. }
  322. /**
  323. * Shows all available HTML document templates
  324. *
  325. * @param string $username
  326. */
  327. function zb_DocsShowAllTemplates($username = '') {
  328. $docpath = DATA_PATH . 'documents/';
  329. $headerspath = $docpath . 'headers/';
  330. $templatespath = $docpath . 'templates/';
  331. $allheaders = rcms_scandir($headerspath);
  332. if ($username != '') {
  333. $userlink = '&username=' . $username;
  334. } else {
  335. $userlink = '';
  336. }
  337. $tablecells = wf_TableCell(__('Document name'));
  338. $tablecells .= wf_TableCell(__('Actions'));
  339. $tablerows = wf_TableRow($tablecells, 'row1');
  340. if (!empty($allheaders)) {
  341. foreach ($allheaders as $eachdoc) {
  342. if (file_exists($templatespath . $eachdoc)) {
  343. $documenttitle = file_get_contents($headerspath . $eachdoc);
  344. $printlink = '<a href="?module=pl_documents' . $userlink . '&printtemplate=' . $eachdoc . '" target="_BLANK">' . $documenttitle . '</a>';
  345. $actionlinks = wf_JSAlert("?module=pl_documents" . $userlink . "&deletetemplate=" . $eachdoc, web_delete_icon(), 'Removing this may lead to irreparable results');
  346. $actionlinks .= wf_JSAlert("?module=pl_documents" . $userlink . "&edittemplate=" . $eachdoc, web_edit_icon(), 'Are you serious');
  347. $tablecells = wf_TableCell($printlink);
  348. $tablecells .= wf_TableCell($actionlinks);
  349. $tablerows .= wf_TableRow($tablecells, 'row3');
  350. }
  351. }
  352. }
  353. $result = wf_TableBody($tablerows, '100%', '0', 'sortable');
  354. show_window(__('Available document templates'), $result);
  355. }
  356. /**
  357. * Returns HTML document template body by its name
  358. *
  359. * @param string $template
  360. * @return string
  361. */
  362. function zb_DocsLoadTemplate($template) {
  363. $docpath = DATA_PATH . 'documents/';
  364. $templatespath = $docpath . 'templates/';
  365. $result = file_get_contents($templatespath . $template);
  366. return ($result);
  367. }
  368. /**
  369. * Returns HTML document template title by its name
  370. *
  371. * @param string $template
  372. * @return string
  373. */
  374. function zb_DocsLoadTemplateTitle($template) {
  375. $docpath = DATA_PATH . 'documents/';
  376. $headerspath = $docpath . 'headers/';
  377. $result = file_get_contents($headerspath . $template);
  378. return ($result);
  379. }
  380. /**
  381. * Parses HTML document template with some user data
  382. *
  383. * @param string $template
  384. * @param string $login
  385. * @return string
  386. */
  387. function zb_DocsParseTemplate($template, $login) {
  388. $templatebody = zb_DocsLoadTemplate($template);
  389. $alluserdata = zb_TemplateGetAllUserData();
  390. $result = zb_TemplateReplace($login, $templatebody, $alluserdata);
  391. return ($result);
  392. }
  393. /**
  394. * Deletes HTML document template from FS
  395. *
  396. * @param string $template
  397. */
  398. function zb_DocsDeleteTemplate($template) {
  399. $docpath = DATA_PATH . 'documents/';
  400. $headerspath = $docpath . 'headers/';
  401. $templatespath = $docpath . 'templates/';
  402. rcms_delete_files($headerspath . $template);
  403. rcms_delete_files($templatespath . $template);
  404. log_register("DOCS TEMPLATE DELETE " . $template);
  405. }
  406. /**
  407. * Shows HTML document template creation form
  408. *
  409. * @return void
  410. */
  411. function zb_DocsTemplateAddForm() {
  412. $inputs = wf_TextInput('newtemplatetitle', __('New template title'), '', true, '50');
  413. $inputs .= wf_TextArea('newtemplatebody', '', '', true, '80x20');
  414. $inputs .= wf_Submit('Create');
  415. $addform = wf_Form('', 'POST', $inputs, 'glamour');
  416. show_window(__('Create new template'), $addform);
  417. }
  418. /**
  419. * Shows HTML document template editing form
  420. *
  421. * @return void
  422. */
  423. function zb_DocsTemplateEditForm($template) {
  424. $templatebody = zb_DocsLoadTemplate($template);
  425. $templatetitle = zb_DocsLoadTemplateTitle($template);
  426. $inputs = wf_TextInput('edittemplatetitle', __('Edit template title'), $templatetitle, true, '50');
  427. $inputs .= wf_TextArea('edittemplatebody', '', $templatebody, true, '80x20');
  428. $inputs .= wf_Submit('Save');
  429. $addform = wf_Form('', 'POST', $inputs, 'glamour');
  430. show_window(__('Edit document template'), $addform);
  431. }
  432. /**
  433. * Creates new HTML document template
  434. *
  435. * @param string $title
  436. * @param string $body
  437. *
  438. * @return void
  439. */
  440. function zb_DocsTemplateCreate($title, $body) {
  441. $docpath = DATA_PATH . 'documents/';
  442. $headerspath = $docpath . 'headers/';
  443. $templatespath = $docpath . 'templates/';
  444. $newtemplateid = time();
  445. file_put_contents($headerspath . $newtemplateid, $title);
  446. file_put_contents($templatespath . $newtemplateid, $body);
  447. log_register("DOCS TEMPLATE CREATE " . $newtemplateid);
  448. }
  449. /**
  450. * Edits existing HTML document template
  451. *
  452. * @param string $template
  453. * @param string $title
  454. * @param string $body
  455. */
  456. function zb_DocsTemplateEdit($template, $title, $body) {
  457. $docpath = DATA_PATH . 'documents/';
  458. $headerspath = $docpath . 'headers/';
  459. $templatespath = $docpath . 'templates/';
  460. $edittemplateid = $template;
  461. file_put_contents($headerspath . $edittemplateid, $title);
  462. file_put_contents($templatespath . $edittemplateid, $body);
  463. log_register("DOCS TEMPLATE CHANGE " . $edittemplateid);
  464. }
  465. ?>