PageRenderTime 27ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/mailchimp/report/client_mailchimp_export.php

https://gitlab.com/nexxuz/phpBMS
PHP | 292 lines | 164 code | 82 blank | 46 comment | 10 complexity | c93b0dd65b943d46347855222d3ff254 MD5 | raw file
  1. <?php
  2. /*
  3. $Rev: 611 $ | $LastChangedBy: nate $
  4. $LastChangedDate: 2009-06-18 17:26:06 -0600 (Thu, 18 Jun 2009) $
  5. +-------------------------------------------------------------------------+
  6. | Copyright (c) 2004 - 2010, Kreotek LLC |
  7. | All rights reserved. |
  8. +-------------------------------------------------------------------------+
  9. | |
  10. | Redistribution and use in source and binary forms, with or without |
  11. | modification, are permitted provided that the following conditions are |
  12. | met: |
  13. | |
  14. | - Redistributions of source code must retain the above copyright |
  15. | notice, this list of conditions and the following disclaimer. |
  16. | |
  17. | - Redistributions in binary form must reproduce the above copyright |
  18. | notice, this list of conditions and the following disclaimer in the |
  19. | documentation and/or other materials provided with the distribution. |
  20. | |
  21. | - Neither the name of Kreotek LLC nor the names of its contributore may |
  22. | be used to endorse or promote products derived from this software |
  23. | without specific prior written permission. |
  24. | |
  25. | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
  26. | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
  27. | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
  28. | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
  29. | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
  30. | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
  31. | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
  32. | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
  33. | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
  34. | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
  35. | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
  36. | |
  37. +-------------------------------------------------------------------------+
  38. */
  39. if(!class_exists("phpbmsReport"))
  40. include("../../../report/report_class.php");
  41. class MCReport extends phpbmsReport{
  42. var $selectcolumns;
  43. var $selecttable;
  44. var $whereclause="";
  45. var $reportOutput = "";
  46. function MCReport($db, $reportUUID, $tabledefUUID, $variables = NULL){
  47. parent::phpbmsReport($db, $reportUUID, $tabledefUUID);
  48. //next we do the columns
  49. $this->addColumn("Email","`email`");//0
  50. $this->addColumn("First Name","`firstname`");//1
  51. $this->addColumn("Last Name","`lastname`");//2
  52. $this->addColumn("Company","`company`");//3
  53. $this->addColumn("Uuid","`uuid`");//4
  54. $this->addColumn("Type","`type`");//5
  55. $this->addColumn("Id","`id`");//6
  56. $this->selecttable = "`clients`";
  57. }//end method
  58. function processFromPost($variables){
  59. $tempArray = json_decode($variables["columns"], true);
  60. foreach($tempArray as $id)
  61. $this->selectcolumns[] = $this->columns[$id];
  62. $this->selectcolumns = array_reverse($this->selectcolumns);
  63. }//end function processFromPost
  64. function processFromSettings(){
  65. foreach($this->settings as $key=>$value)
  66. if(strpos($key, "column") === 0)
  67. $this->selectcolumns[substr($key,6)-1] = $this->columns[$value];
  68. ksort($this->selectcolumns);
  69. $this->selectcolumns = array_reverse($this->selectcolumns);
  70. }//end function processFromSettings
  71. function addColumn($name, $field, $format = NULL){
  72. $temp = array();
  73. $temp["name"] = $name;
  74. $temp["field"] = $field;
  75. $temp["format"] = $format;
  76. $this->columns[] = $temp;
  77. }//end method
  78. function generate(){
  79. $this->whereClause = $_SESSION["printing"]["whereclause"];
  80. if($this->whereClause=="")
  81. $this->whereclause="WHERE clients.id != -1";
  82. if($this->whereClause!="")
  83. $this->whereClause = " WHERE (".substr($this->whereClause,6).") ";
  84. $querystatement = "SELECT ";
  85. foreach($this->selectcolumns as $thecolumn)
  86. $querystatement .= $thecolumn["field"]." AS `".$thecolumn["name"]."`,";
  87. $querystatement = substr($querystatement, 0, -1);
  88. $querystatement .= " FROM ".$this->selecttable.$this->whereclause;
  89. $queryresult = $this->db->query($querystatement);
  90. $num_fields = $this->db->numFields($queryresult);
  91. for($i=0;$i<$num_fields;$i++)
  92. $this->reportOutput .= ",".$this->db->fieldName($queryresult, $i);
  93. $this->reportOutput = substr($this->reportOutput, 1)."\n";
  94. while($therecord = $this->db->fetchArray($queryresult)){
  95. $line = "";
  96. foreach($therecord as $value)
  97. $line .= ',"'.mysql_real_escape_string($value).'"';
  98. $line = substr($line, 1)."\n";
  99. $this->reportOutput .= $line;
  100. }//endwhile
  101. $this->reportOutput = "----- The headings should be deleted before importing into MailChimp -----\n".$this->reportOutput;
  102. $this->reportOutput = substr($this->reportOutput, 0, strlen($this->reportOutput)-1);
  103. }
  104. function output(){
  105. header("Content-type: text/plain");
  106. header('Content-Disposition: attachment; filename="clients_mailchimp_export.csv"');
  107. echo $this->reportOutput;
  108. }//end function --output--
  109. function showOptions($what){
  110. ?><option value="0">----- Choose One -----</option>
  111. <?php
  112. $i=0;
  113. foreach($this->$what as $value){
  114. ?><option value="<?php echo $i+1; ?>"><?php echo $value["name"];?></option>
  115. <?php
  116. $i++;
  117. }// endforeach
  118. }//end mothd
  119. function showSelectScreen(){
  120. global $phpbms;
  121. $pageTitle="Invoice Total";
  122. $phpbms->showMenu = false;
  123. $phpbms->cssIncludes[] = "pages/totalreports.css";
  124. $phpbms->jsIncludes[] = "modules/bms/javascript/totalreports.js";
  125. include("header.php");
  126. ?>
  127. <div class="bodyline">
  128. <h1>Invoice Total Options</h1>
  129. <form id="GroupForm" action="<?php echo htmlentities($_SERVER["PHP_SELF"])?>" method="post" name="GroupForm">
  130. <fieldset>
  131. <legend>report</legend>
  132. <p>
  133. <label for="reporttitle">report title</label><br />
  134. <input type="text" name="reporttitle" id="reporttitle" size="45"/>
  135. </p>
  136. </fieldset>
  137. <fieldset>
  138. <legend>groupings</legend>
  139. <input id="groupings" type="hidden" name="groupings"/>
  140. <div id="theGroups">
  141. <div id="Group1">
  142. <select id="Group1Field">
  143. <?php $this->showOptions("groupings")?>
  144. </select>
  145. <button type="button" id="Group1Minus" class="graphicButtons buttonMinusDisabled"><span>-</span></button>
  146. <button type="button" id="Group1Plus" class="graphicButtons buttonPlus"><span>+</span></button>
  147. </div>
  148. </div>
  149. </fieldset>
  150. <fieldset>
  151. <legend>columns</legend>
  152. <input id="columns" type="hidden" name="columns"/>
  153. <div id="theColumns">
  154. <div id="Column1">
  155. <select id="Column1Field">
  156. <?php $this->showOptions("columns")?>
  157. </select>
  158. <button type="button" id="Column1Minus" class="graphicButtons buttonMinusDisabled"><span>-</span></button>
  159. <button type="button" id="Column1Plus" class="graphicButtons buttonPlus"><span>+</span></button>
  160. </div>
  161. </div>
  162. </fieldset>
  163. <fieldset>
  164. <legend>Options</legend>
  165. <p>
  166. <label for="showwhat">information shown</label><br />
  167. <select name="showwhat" id="showwhat">
  168. <option selected="selected" value="totals">Totals Only</option>
  169. <option value="invoices">Invoices</option>
  170. <option value="lineitems">Invoices &amp; Line Items</option>
  171. </select>
  172. </p>
  173. </fieldset>
  174. <p align="right">
  175. <button id="print" type="button" class="Buttons">Print</button>
  176. <button id="cancel" type="button" class="Buttons">Cancel</button>
  177. </p>
  178. </form>
  179. </div>
  180. <?php
  181. include("footer.php");
  182. }//end method
  183. }//endclass
  184. /**
  185. * PROCESSING
  186. * =============================================================================
  187. */
  188. if(!isset($noOutput)){
  189. require("../../../include/session.php");
  190. checkForReportArguments();
  191. $report = new MCReport($db, $_GET["rid"], $_GET["tid"]);
  192. if(isset($_POST["columns"])){
  193. $report->processFromPost($_POST);
  194. $report->generate();
  195. $report->output();
  196. } elseif(isset($report->settings["column1"])) {
  197. $report->processFromSettings();
  198. $report->generate();
  199. $report->output();
  200. } else {
  201. $report->showSelectScreen();
  202. }//endif
  203. }//endif
  204. /**
  205. * When adding a new report record, the add/edit needs to know what the class
  206. * name is so that it can instantiate it, and grab it's default settings.
  207. */
  208. if(isset($addingReportRecord))
  209. $reportClass = "MCReport";
  210. ?>