mymoduleindex.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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"])) {
  29. $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
  30. }
  31. // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
  32. $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
  33. while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
  34. $i--; $j--;
  35. }
  36. if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
  37. $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
  38. }
  39. if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
  40. $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
  41. }
  42. // Try main.inc.php using relative path
  43. if (!$res && file_exists("../main.inc.php")) {
  44. $res = @include "../main.inc.php";
  45. }
  46. if (!$res && file_exists("../../main.inc.php")) {
  47. $res = @include "../../main.inc.php";
  48. }
  49. if (!$res && file_exists("../../../main.inc.php")) {
  50. $res = @include "../../../main.inc.php";
  51. }
  52. if (!$res) {
  53. die("Include of main fails");
  54. }
  55. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  56. // Load translation files required by the page
  57. $langs->loadLangs(array("mymodule@mymodule"));
  58. $action = GETPOST('action', 'aZ09');
  59. $max = 5;
  60. $now = dol_now();
  61. // Security check - Protection if external user
  62. $socid = GETPOST('socid', 'int');
  63. if (isset($user->socid) && $user->socid > 0) {
  64. $action = '';
  65. $socid = $user->socid;
  66. }
  67. // Security check (enable the most restrictive one)
  68. //if ($user->socid > 0) accessforbidden();
  69. //if ($user->socid > 0) $socid = $user->socid;
  70. //if (!isModEnabled('mymodule')) {
  71. // accessforbidden('Module not enabled');
  72. //}
  73. //if (! $user->hasRight('mymodule', 'myobject', 'read')) {
  74. // accessforbidden();
  75. //}
  76. //restrictedArea($user, 'mymodule', 0, 'mymodule_myobject', 'myobject', '', 'rowid');
  77. //if (empty($user->admin)) {
  78. // accessforbidden('Must be admin');
  79. //}
  80. /*
  81. * Actions
  82. */
  83. // None
  84. /*
  85. * View
  86. */
  87. $form = new Form($db);
  88. $formfile = new FormFile($db);
  89. llxHeader("", $langs->trans("MyModuleArea"));
  90. print load_fiche_titre($langs->trans("MyModuleArea"), '', 'mymodule.png@mymodule');
  91. print '<div class="fichecenter"><div class="fichethirdleft">';
  92. /* BEGIN MODULEBUILDER DRAFT MYOBJECT
  93. // Draft MyObject
  94. if (isModEnabled('mymodule') && $user->rights->mymodule->read)
  95. {
  96. $langs->load("orders");
  97. $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";
  98. $sql.= ", s.code_client";
  99. $sql.= " FROM ".MAIN_DB_PREFIX."commande as c";
  100. $sql.= ", ".MAIN_DB_PREFIX."societe as s";
  101. if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  102. $sql.= " WHERE c.fk_soc = s.rowid";
  103. $sql.= " AND c.fk_statut = 0";
  104. $sql.= " AND c.entity IN (".getEntity('commande').")";
  105. if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  106. if ($socid) $sql.= " AND c.fk_soc = ".((int) $socid);
  107. $resql = $db->query($sql);
  108. if ($resql)
  109. {
  110. $total = 0;
  111. $num = $db->num_rows($resql);
  112. print '<table class="noborder centpercent">';
  113. print '<tr class="liste_titre">';
  114. print '<th colspan="3">'.$langs->trans("DraftMyObjects").($num?'<span class="badge marginleftonlyshort">'.$num.'</span>':'').'</th></tr>';
  115. $var = true;
  116. if ($num > 0)
  117. {
  118. $i = 0;
  119. while ($i < $num)
  120. {
  121. $obj = $db->fetch_object($resql);
  122. print '<tr class="oddeven"><td class="nowrap">';
  123. $myobjectstatic->id=$obj->rowid;
  124. $myobjectstatic->ref=$obj->ref;
  125. $myobjectstatic->ref_client=$obj->ref_client;
  126. $myobjectstatic->total_ht = $obj->total_ht;
  127. $myobjectstatic->total_tva = $obj->total_tva;
  128. $myobjectstatic->total_ttc = $obj->total_ttc;
  129. print $myobjectstatic->getNomUrl(1);
  130. print '</td>';
  131. print '<td class="nowrap">';
  132. print '</td>';
  133. print '<td class="right" class="nowrap">'.price($obj->total_ttc).'</td></tr>';
  134. $i++;
  135. $total += $obj->total_ttc;
  136. }
  137. if ($total>0)
  138. {
  139. print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td colspan="2" class="right">'.price($total)."</td></tr>";
  140. }
  141. }
  142. else
  143. {
  144. print '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("NoOrder").'</td></tr>';
  145. }
  146. print "</table><br>";
  147. $db->free($resql);
  148. }
  149. else
  150. {
  151. dol_print_error($db);
  152. }
  153. }
  154. END MODULEBUILDER DRAFT MYOBJECT */
  155. print '</div><div class="fichetwothirdright">';
  156. $NBMAX = getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT');
  157. $max = getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT');
  158. /* BEGIN MODULEBUILDER LASTMODIFIED MYOBJECT
  159. // Last modified myobject
  160. if (isModEnabled('mymodule') && $user->rights->mymodule->read)
  161. {
  162. $sql = "SELECT s.rowid, s.ref, s.label, s.date_creation, s.tms";
  163. $sql.= " FROM ".MAIN_DB_PREFIX."mymodule_myobject as s";
  164. //if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  165. $sql.= " WHERE s.entity IN (".getEntity($myobjectstatic->element).")";
  166. //if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  167. //if ($socid) $sql.= " AND s.rowid = $socid";
  168. $sql .= " ORDER BY s.tms DESC";
  169. $sql .= $db->plimit($max, 0);
  170. $resql = $db->query($sql);
  171. if ($resql)
  172. {
  173. $num = $db->num_rows($resql);
  174. $i = 0;
  175. print '<table class="noborder centpercent">';
  176. print '<tr class="liste_titre">';
  177. print '<th colspan="2">';
  178. print $langs->trans("BoxTitleLatestModifiedMyObjects", $max);
  179. print '</th>';
  180. print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
  181. print '</tr>';
  182. if ($num)
  183. {
  184. while ($i < $num)
  185. {
  186. $objp = $db->fetch_object($resql);
  187. $myobjectstatic->id=$objp->rowid;
  188. $myobjectstatic->ref=$objp->ref;
  189. $myobjectstatic->label=$objp->label;
  190. $myobjectstatic->status = $objp->status;
  191. print '<tr class="oddeven">';
  192. print '<td class="nowrap">'.$myobjectstatic->getNomUrl(1).'</td>';
  193. print '<td class="right nowrap">';
  194. print "</td>";
  195. print '<td class="right nowrap">'.dol_print_date($db->jdate($objp->tms), 'day')."</td>";
  196. print '</tr>';
  197. $i++;
  198. }
  199. $db->free($resql);
  200. } else {
  201. print '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
  202. }
  203. print "</table><br>";
  204. }
  205. }
  206. */
  207. print '</div></div>';
  208. // End of page
  209. llxFooter();
  210. $db->close();