index.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <?php
  2. /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/adherents/stats/index.php
  21. * \ingroup member
  22. * \brief Page of subscription members statistics
  23. */
  24. require("../../main.inc.php");
  25. require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherentstats.class.php");
  26. require_once(DOL_DOCUMENT_ROOT."/core/class/dolgraph.class.php");
  27. require_once(DOL_DOCUMENT_ROOT."/lib/member.lib.php");
  28. $WIDTH=500;
  29. $HEIGHT=200;
  30. $userid=GETPOST('userid'); if ($userid < 0) $userid=0;
  31. $socid=GETPOST('socid'); if ($socid < 0) $socid=0;
  32. // Security check
  33. if ($user->societe_id > 0)
  34. {
  35. $action = '';
  36. $socid = $user->societe_id;
  37. }
  38. $year = strftime("%Y", time());
  39. $startyear=$year-2;
  40. $endyear=$year;
  41. /*
  42. * View
  43. */
  44. $form=new Form($db);
  45. $langs->load("propal");
  46. llxHeader();
  47. print_fiche_titre($langs->trans("SubscriptionsStatistics"), $mesg);
  48. $dir=$conf->adherent->dir_temp;
  49. create_exdir($dir);
  50. $stats = new AdherentStats($db, $socid, $userid);
  51. // Build graphic number of object
  52. $data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);
  53. //var_dump($data);
  54. // $data = array(array('Lib',val1,val2,val3),...)
  55. $filenamenb = $dir.'/subscriptionsnbinyear-'.$year.'.png';
  56. $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=memberstats&file=subscriptionsnbinyear-'.$year.'.png';
  57. $px = new DolGraph();
  58. $mesg = $px->isGraphKo();
  59. if (! $mesg)
  60. {
  61. $px->SetData($data);
  62. $px->SetPrecisionY(0);
  63. $i=$startyear;
  64. while ($i <= $endyear)
  65. {
  66. $legend[]=$i;
  67. $i++;
  68. }
  69. $px->SetLegend($legend);
  70. $px->SetMaxValue($px->GetCeilMaxValue());
  71. $px->SetMinValue(min(0,$px->GetFloorMinValue()));
  72. $px->SetWidth($WIDTH);
  73. $px->SetHeight($HEIGHT);
  74. $px->SetYLabel($langs->trans("NbOfSubscriptions"));
  75. $px->SetShading(3);
  76. $px->SetHorizTickIncrement(1);
  77. $px->SetPrecisionY(0);
  78. $px->mode='depth';
  79. $px->SetTitle($langs->trans("NbOfSubscriptions"));
  80. $px->draw($filenamenb);
  81. }
  82. // Build graphic amount of object
  83. $data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear);
  84. //var_dump($data);
  85. // $data = array(array('Lib',val1,val2,val3),...)
  86. $filenameamount = $dir.'/subscriptionsamountinyear-'.$year.'.png';
  87. $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=memberstats&file=subscriptionsamountinyear-'.$year.'.png';
  88. $px = new DolGraph();
  89. $mesg = $px->isGraphKo();
  90. if (! $mesg)
  91. {
  92. $px->SetData($data);
  93. $px->SetPrecisionY(0);
  94. $i=$startyear;
  95. while ($i <= $endyear)
  96. {
  97. $legend[]=$i;
  98. $i++;
  99. }
  100. $px->SetLegend($legend);
  101. $px->SetMaxValue($px->GetCeilMaxValue());
  102. $px->SetMinValue(min(0,$px->GetFloorMinValue()));
  103. $px->SetWidth($WIDTH);
  104. $px->SetHeight($HEIGHT);
  105. $px->SetYLabel($langs->trans("AmountOfSubscriptions"));
  106. $px->SetShading(3);
  107. $px->SetHorizTickIncrement(1);
  108. $px->SetPrecisionY(0);
  109. $px->mode='depth';
  110. $px->SetTitle($langs->trans("AmountOfSubscriptions"));
  111. $px->draw($filenameamount);
  112. }
  113. $head = member_stats_prepare_head($adh);
  114. dol_fiche_head($head, 'statssubscription', $langs->trans("Statistics"), 0, 'user');
  115. print '<table class="notopnoleftnopadd" width="100%"><tr>';
  116. print '<td align="center" valign="top">';
  117. // Show filter box
  118. /*print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  119. print '<table class="border" width="100%">';
  120. print '<tr><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
  121. print '<tr><td>'.$langs->trans("Member").'</td><td>';
  122. $filter='s.client in (1,2,3)';
  123. print $form->select_company($id,'memberid',$filter,1);
  124. print '</td></tr>';
  125. print '<tr><td>'.$langs->trans("User").'</td><td>';
  126. print $form->select_users($userid,'userid',1);
  127. print '</td></tr>';
  128. print '<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans("Refresh").'"></td></tr>';
  129. print '</table>';
  130. print '</form>';
  131. print '<br><br>';
  132. */
  133. // Show array
  134. $data = $stats->getAllByYear();
  135. print '<table class="border" width="100%">';
  136. print '<tr height="24">';
  137. print '<td align="center">'.$langs->trans("Year").'</td>';
  138. print '<td align="center">'.$langs->trans("NbOfSubscriptions").'</td>';
  139. print '<td align="center">'.$langs->trans("AmountTotal").'</td>';
  140. print '<td align="center">'.$langs->trans("AmountAverage").'</td>';
  141. print '</tr>';
  142. $oldyear=0;
  143. foreach ($data as $val)
  144. {
  145. $year = $val['year'];
  146. print $avg;
  147. while ($oldyear > $year+1)
  148. { // If we have empty year
  149. $oldyear--;
  150. print '<tr height="24">';
  151. print '<td align="center">';
  152. print '<a href="month.php?year='.$oldyear.'&amp;mode='.$mode.'">';
  153. print $oldyear;
  154. print '</a>';
  155. print '</td>';
  156. print '<td align="right">0</td>';
  157. print '<td align="right">0</td>';
  158. print '<td align="right">0</td>';
  159. print '</tr>';
  160. }
  161. print '<tr height="24">';
  162. print '<td align="center">';
  163. //print '<a href="month.php?year='.$year.'">';
  164. print $year;
  165. //print '</a>';
  166. print '</td>';
  167. print '<td align="right">'.$val['nb'].'</td>';
  168. print '<td align="right">'.price(price2num($val['total'],'MT'),1).'</td>';
  169. print '<td align="right">'.price(price2num($val['avg'],'MT'),1).'</td>';
  170. print '</tr>';
  171. $oldyear=$year;
  172. }
  173. print '</table>';
  174. print '</td>';
  175. print '<td align="center" valign="top">';
  176. // Show graphs
  177. print '<table class="border" width="100%"><tr valign="top"><td align="center">';
  178. if ($mesg) { print $mesg; }
  179. else {
  180. print '<img src="'.$fileurlnb.'" title="'.$langs->trans("NbOfSubscriptions").'" alt="'.$langs->trans("NbOfSubscriptions").'">';
  181. print "<br>\n";
  182. print '<img src="'.$fileurlamount.'" title="'.$langs->trans("AmountTotal").'" alt="'.$langs->trans("AmountTotal").'">';
  183. }
  184. print '</td></tr></table>';
  185. print '</td></tr></table>';
  186. dol_fiche_end();
  187. $db->close();
  188. llxFooter();
  189. ?>