index.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?php
  2. if (cfr('PLDOCS')) {
  3. $altercfg = $ubillingConfig->getAlter();
  4. //old html templates
  5. if (!$altercfg['DOCX_SUPPORT']) {
  6. if (isset($_GET['username'])) {
  7. $login = vf($_GET['username']);
  8. //delete subroutine
  9. if (isset($_GET['deletetemplate'])) {
  10. zb_DocsDeleteTemplate($_GET['deletetemplate']);
  11. rcms_redirect("?module=pl_documents&username=" . $login);
  12. }
  13. if (isset($_GET['addtemplate'])) {
  14. //add subroutine
  15. if (wf_CheckPost(array('newtemplatetitle', 'newtemplatebody'))) {
  16. zb_DocsTemplateCreate($_POST['newtemplatetitle'], $_POST['newtemplatebody']);
  17. rcms_redirect("?module=pl_documents&username=" . $login);
  18. }
  19. //show add form
  20. zb_DocsTemplateAddForm();
  21. }
  22. if (isset($_GET['edittemplate'])) {
  23. //edit subroutine
  24. if (wf_CheckPost(array('edittemplatetitle', 'edittemplatebody'))) {
  25. zb_DocsTemplateEdit($_GET['edittemplate'], $_POST['edittemplatetitle'], $_POST['edittemplatebody']);
  26. rcms_redirect("?module=pl_documents&username=" . $login);
  27. }
  28. //show edit form
  29. zb_DocsTemplateEditForm($_GET['edittemplate']);
  30. }
  31. if (!isset($_GET['printtemplate'])) {
  32. //showing document templates list by default
  33. if ((!isset($_GET['addtemplate'])) AND ( !isset($_GET['edittemplate']))) {
  34. show_window('', wf_Link('?module=pl_documents&username=' . $login . '&addtemplate', web_icon_create() . ' ' . __('Create new document template'), true, 'ubButton'));
  35. } else {
  36. show_window('', wf_BackLink('?module=pl_documents&username=' . $login, '', true));
  37. }
  38. zb_DocsShowAllTemplates($login);
  39. show_window('', web_UserControls($login));
  40. } else {
  41. //document print subroutine
  42. $parsed_template = zb_DocsParseTemplate($_GET['printtemplate'], $login);
  43. print($parsed_template);
  44. die();
  45. }
  46. }
  47. } else {
  48. //new docx templates processing
  49. $documents = new ProfileDocuments();
  50. if (wf_CheckGet(array('username'))) {
  51. $documents->setLogin($_GET['username']);
  52. }
  53. //template printing subroutine
  54. if (wf_CheckGet(array('print'))) {
  55. //back link
  56. show_window('', wf_BackLink('?module=pl_documents&username=' . $documents->getLogin(), '', true));
  57. $docId = vf($_GET['print'], 3);
  58. $availableTemplates = $documents->getTemplates();
  59. $templatePath = $documents::TEMPLATES_PATH;
  60. $documentsSavePath = $documents::DOCUMENTS_PATH;
  61. $templateFile = $availableTemplates[$docId]['path'];
  62. $templateName = $availableTemplates[$docId]['name'];
  63. $fullPath = $templatePath . $templateFile;
  64. $saveFileName = $documents->getLogin() . '_' . $docId . '_' . zb_rand_string(8) . '.docx';
  65. $saveFullPath = $documentsSavePath . $saveFileName;
  66. $documents->loadAllUserData();
  67. $templateData = $documents->getUserData();
  68. $userAgentData = $documents->getUserAgentData();
  69. $templateData = array_merge($templateData, $userAgentData);
  70. if (wf_checkget(array('custom'))) {
  71. show_window(__('Custom template fields'), $documents->customDocumentFieldsForm());
  72. if (wf_CheckPost(array('customfields'))) {
  73. $documents->setCustomFields();
  74. $templateData = array_merge($templateData, $documents->getCustomFields());
  75. //parse document template
  76. $docx = new DOCXTemplate($fullPath);
  77. $docx->set($templateData);
  78. $docx->saveAs($saveFullPath);
  79. //registering generated custom fields document
  80. $documents->registerDocument($documents->getLogin(), $docId, $saveFileName);
  81. //output
  82. zb_DownloadFile($saveFullPath, 'docx');
  83. }
  84. } else {
  85. //parse document template
  86. $docx = new DOCXTemplate($fullPath);
  87. $docx->set($templateData);
  88. $docx->saveAs($saveFullPath);
  89. //registering generated document
  90. $documents->registerDocument($documents->getLogin(), $docId, $saveFileName);
  91. //output
  92. zb_DownloadFile($saveFullPath, 'docx');
  93. }
  94. } else {
  95. //template downloading
  96. if (wf_CheckGet(array('download'))) {
  97. zb_DownloadFile($documents::TEMPLATES_PATH . $_GET['download'], 'docx');
  98. }
  99. //template deletion
  100. if (wf_CheckGet(array('deletetemplate'))) {
  101. $documents->deleteTemplate($_GET['deletetemplate']);
  102. rcms_redirect('?module=pl_documents&username=' . $documents->getLogin());
  103. }
  104. //template editing
  105. if (wf_CheckPost(array('editsometemplateid'))) {
  106. $documents->saveTemplate();
  107. rcms_redirect('?module=pl_documents&username=' . $documents->getLogin());
  108. }
  109. //showing available templates
  110. show_window(__('Available document templates'), $documents->renderTemplatesList());
  111. //uploading new templates
  112. $uploadControl = wf_modal(wf_img('skins/photostorage_upload.png') . ' ' . __('Upload template'), __('Upload template'), $documents->uploadForm(), 'ubButton', '600', '300');
  113. show_window(__('Settings'), $uploadControl);
  114. //template upload subroutine
  115. if (wf_CheckPost(array('uploadtemplate'))) {
  116. $documents->doUpload();
  117. rcms_redirect('?module=pl_documents&username=' . $documents->getLogin());
  118. }
  119. //loading current user documents data
  120. $documents->loadUserDocuments($documents->getLogin());
  121. //document visibility editing
  122. if (wf_CheckPost(array('chvisdocumentid'))) {
  123. $documents->saveDocumentVisibility();
  124. rcms_redirect('?module=pl_documents&username=' . $documents->getLogin());
  125. }
  126. //showing user personal documents
  127. show_window(__('Previously generated documents for this user'), $documents->renderUserDocuments());
  128. }
  129. //existing document downloading
  130. if (wf_CheckGet(array('documentdownload'))) {
  131. zb_DownloadFile($documents::DOCUMENTS_PATH . $_GET['documentdownload'], 'docx');
  132. }
  133. //document deletion from database
  134. if (wf_CheckGet(array('deletedocument'))) {
  135. $documents->unregisterDocument($_GET['deletedocument']);
  136. rcms_redirect('?module=pl_documents&username=' . $documents->getLogin());
  137. }
  138. show_window('', web_UserControls($documents->getLogin()));
  139. }
  140. } else {
  141. show_error(__('You cant control this module'));
  142. }
  143. ?>