mymoduleindex.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <?php
  2. /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/modulebuilder/template/mymoduleindex.php
  22. * \ingroup mymodule
  23. * \brief Home page of mymodule top menu
  24. */
  25. // Load Dolibarr environment
  26. $res = 0;
  27. // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
  28. if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
  29. // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
  30. $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
  31. while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; }
  32. if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
  33. if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
  34. // Try main.inc.php using relative path
  35. if (!$res && file_exists("../main.inc.php")) $res = @include "../main.inc.php";
  36. if (!$res && file_exists("../../main.inc.php")) $res = @include "../../main.inc.php";
  37. if (!$res && file_exists("../../../main.inc.php")) $res = @include "../../../main.inc.php";
  38. if (!$res) die("Include of main fails");
  39. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  40. // Load translation files required by the page
  41. $langs->loadLangs(array("mymodule@mymodule"));
  42. $action = GETPOST('action', 'alpha');
  43. // Security check
  44. //if (! $user->rights->mymodule->myobject->read) accessforbidden();
  45. $socid = GETPOST('socid', 'int');
  46. if (isset($user->socid) && $user->socid > 0)
  47. {
  48. $action = '';
  49. $socid = $user->socid;
  50. }
  51. $max = 5;
  52. $now = dol_now();
  53. /*
  54. * Actions
  55. */
  56. // None
  57. /*
  58. * View
  59. */
  60. $form = new Form($db);
  61. $formfile = new FormFile($db);
  62. llxHeader("", $langs->trans("MyModuleArea"));
  63. print load_fiche_titre($langs->trans("MyModuleArea"), '', 'mymodule.png@mymodule');
  64. print '<div class="fichecenter"><div class="fichethirdleft">';
  65. /* BEGIN MODULEBUILDER DRAFT MYOBJECT
  66. // Draft MyObject
  67. if (! empty($conf->mymodule->enabled) && $user->rights->mymodule->read)
  68. {
  69. $langs->load("orders");
  70. $sql = "SELECT c.rowid, c.ref, c.ref_client, c.total_ht, c.tva as total_tva, c.total_ttc, s.rowid as socid, s.nom as name, s.client, s.canvas";
  71. $sql.= ", s.code_client";
  72. $sql.= " FROM ".MAIN_DB_PREFIX."commande as c";
  73. $sql.= ", ".MAIN_DB_PREFIX."societe as s";
  74. if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  75. $sql.= " WHERE c.fk_soc = s.rowid";
  76. $sql.= " AND c.fk_statut = 0";
  77. $sql.= " AND c.entity IN (".getEntity('commande').")";
  78. if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  79. if ($socid) $sql.= " AND c.fk_soc = ".$socid;
  80. $resql = $db->query($sql);
  81. if ($resql)
  82. {
  83. $total = 0;
  84. $num = $db->num_rows($resql);
  85. print '<table class="noborder centpercent">';
  86. print '<tr class="liste_titre">';
  87. print '<th colspan="3">'.$langs->trans("DraftOrders").($num?'<span class="badge marginleftonlyshort">'.$num.'</span>':'').'</th></tr>';
  88. $var = true;
  89. if ($num > 0)
  90. {
  91. $i = 0;
  92. while ($i < $num)
  93. {
  94. $obj = $db->fetch_object($resql);
  95. print '<tr class="oddeven"><td class="nowrap">';
  96. $orderstatic->id=$obj->rowid;
  97. $orderstatic->ref=$obj->ref;
  98. $orderstatic->ref_client=$obj->ref_client;
  99. $orderstatic->total_ht = $obj->total_ht;
  100. $orderstatic->total_tva = $obj->total_tva;
  101. $orderstatic->total_ttc = $obj->total_ttc;
  102. print $orderstatic->getNomUrl(1);
  103. print '</td>';
  104. print '<td class="nowrap">';
  105. $companystatic->id=$obj->socid;
  106. $companystatic->name=$obj->name;
  107. $companystatic->client=$obj->client;
  108. $companystatic->code_client = $obj->code_client;
  109. $companystatic->code_fournisseur = $obj->code_fournisseur;
  110. $companystatic->canvas=$obj->canvas;
  111. print $companystatic->getNomUrl(1,'customer',16);
  112. print '</td>';
  113. print '<td class="right" class="nowrap">'.price($obj->total_ttc).'</td></tr>';
  114. $i++;
  115. $total += $obj->total_ttc;
  116. }
  117. if ($total>0)
  118. {
  119. print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td colspan="2" class="right">'.price($total)."</td></tr>";
  120. }
  121. }
  122. else
  123. {
  124. print '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("NoOrder").'</td></tr>';
  125. }
  126. print "</table><br>";
  127. $db->free($resql);
  128. }
  129. else
  130. {
  131. dol_print_error($db);
  132. }
  133. }
  134. END MODULEBUILDER DRAFT MYOBJECT */
  135. print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
  136. $NBMAX = 3;
  137. $max = 3;
  138. /* BEGIN MODULEBUILDER LASTMODIFIED MYOBJECT
  139. // Last modified myobject
  140. if (! empty($conf->mymodule->enabled) && $user->rights->mymodule->read)
  141. {
  142. $sql = "SELECT s.rowid, s.nom as name, s.client, s.datec, s.tms, s.canvas";
  143. $sql.= ", s.code_client";
  144. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  145. if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  146. $sql.= " WHERE s.client IN (1, 2, 3)";
  147. $sql.= " AND s.entity IN (".getEntity($companystatic->element).")";
  148. if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  149. if ($socid) $sql.= " AND s.rowid = $socid";
  150. $sql .= " ORDER BY s.tms DESC";
  151. $sql .= $db->plimit($max, 0);
  152. $resql = $db->query($sql);
  153. if ($resql)
  154. {
  155. $num = $db->num_rows($resql);
  156. $i = 0;
  157. print '<table class="noborder centpercent">';
  158. print '<tr class="liste_titre">';
  159. print '<th colspan="2">';
  160. if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print $langs->trans("BoxTitleLastCustomersOrProspects",$max);
  161. else if (! empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print $langs->trans("BoxTitleLastModifiedProspects",$max);
  162. else print $langs->trans("BoxTitleLastModifiedCustomers",$max);
  163. print '</th>';
  164. print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
  165. print '</tr>';
  166. if ($num)
  167. {
  168. while ($i < $num)
  169. {
  170. $objp = $db->fetch_object($resql);
  171. $companystatic->id=$objp->rowid;
  172. $companystatic->name=$objp->name;
  173. $companystatic->client=$objp->client;
  174. $companystatic->code_client = $objp->code_client;
  175. $companystatic->code_fournisseur = $objp->code_fournisseur;
  176. $companystatic->canvas=$objp->canvas;
  177. print '<tr class="oddeven">';
  178. print '<td class="nowrap">'.$companystatic->getNomUrl(1,'customer',48).'</td>';
  179. print '<td class="right nowrap">';
  180. print $companystatic->getLibCustProspStatut();
  181. print "</td>";
  182. print '<td class="right nowrap">'.dol_print_date($db->jdate($objp->tms),'day')."</td>";
  183. print '</tr>';
  184. $i++;
  185. }
  186. $db->free($resql);
  187. }
  188. else
  189. {
  190. print '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
  191. }
  192. print "</table><br>";
  193. }
  194. }
  195. */
  196. print '</div></div></div>';
  197. // End of page
  198. llxFooter();
  199. $db->close();