webhookindex.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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 webhook/webhookindex.php
  22. * \ingroup webhook
  23. * \brief Home page of webhook 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("webhook@webhook"));
  58. $action = GETPOST('action', 'aZ09');
  59. // Security check
  60. // if (! $user->rights->webhook->myobject->read) {
  61. // accessforbidden();
  62. // }
  63. $socid = GETPOST('socid', 'int');
  64. if (isset($user->socid) && $user->socid > 0) {
  65. $action = '';
  66. $socid = $user->socid;
  67. }
  68. $max = 5;
  69. $now = dol_now();
  70. /*
  71. * Actions
  72. */
  73. // None
  74. /*
  75. * View
  76. */
  77. $form = new Form($db);
  78. $formfile = new FormFile($db);
  79. llxHeader("", $langs->trans("WebhookArea"));
  80. print load_fiche_titre($langs->trans("WebhookArea"), '', 'webhook.png@webhook');
  81. print '<div class="fichecenter"><div class="fichethirdleft">';
  82. /* BEGIN MODULEBUILDER DRAFT MYOBJECT
  83. // Draft MyObject
  84. if (! empty($conf->webhook->enabled) && $user->rights->webhook->read)
  85. {
  86. $langs->load("orders");
  87. $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";
  88. $sql.= ", s.code_client";
  89. $sql.= " FROM ".MAIN_DB_PREFIX."commande as c";
  90. $sql.= ", ".MAIN_DB_PREFIX."societe as s";
  91. if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  92. $sql.= " WHERE c.fk_soc = s.rowid";
  93. $sql.= " AND c.fk_statut = 0";
  94. $sql.= " AND c.entity IN (".getEntity('commande').")";
  95. if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  96. if ($socid) $sql.= " AND c.fk_soc = ".((int) $socid);
  97. $resql = $db->query($sql);
  98. if ($resql)
  99. {
  100. $total = 0;
  101. $num = $db->num_rows($resql);
  102. print '<table class="noborder centpercent">';
  103. print '<tr class="liste_titre">';
  104. print '<th colspan="3">'.$langs->trans("DraftMyObjects").($num?'<span class="badge marginleftonlyshort">'.$num.'</span>':'').'</th></tr>';
  105. $var = true;
  106. if ($num > 0)
  107. {
  108. $i = 0;
  109. while ($i < $num)
  110. {
  111. $obj = $db->fetch_object($resql);
  112. print '<tr class="oddeven"><td class="nowrap">';
  113. $myobjectstatic->id=$obj->rowid;
  114. $myobjectstatic->ref=$obj->ref;
  115. $myobjectstatic->ref_client=$obj->ref_client;
  116. $myobjectstatic->total_ht = $obj->total_ht;
  117. $myobjectstatic->total_tva = $obj->total_tva;
  118. $myobjectstatic->total_ttc = $obj->total_ttc;
  119. print $myobjectstatic->getNomUrl(1);
  120. print '</td>';
  121. print '<td class="nowrap">';
  122. print '</td>';
  123. print '<td class="right" class="nowrap">'.price($obj->total_ttc).'</td></tr>';
  124. $i++;
  125. $total += $obj->total_ttc;
  126. }
  127. if ($total>0)
  128. {
  129. print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td colspan="2" class="right">'.price($total)."</td></tr>";
  130. }
  131. }
  132. else
  133. {
  134. print '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("NoOrder").'</td></tr>';
  135. }
  136. print "</table><br>";
  137. $db->free($resql);
  138. }
  139. else
  140. {
  141. dol_print_error($db);
  142. }
  143. }
  144. END MODULEBUILDER DRAFT MYOBJECT */
  145. print '</div><div class="fichetwothirdright">';
  146. $NBMAX = $conf->global->MAIN_SIZE_SHORTLIST_LIMIT;
  147. $max = $conf->global->MAIN_SIZE_SHORTLIST_LIMIT;
  148. /* BEGIN MODULEBUILDER LASTMODIFIED MYOBJECT
  149. // Last modified myobject
  150. if (! empty($conf->webhook->enabled) && $user->rights->webhook->read)
  151. {
  152. $sql = "SELECT s.rowid, s.ref, s.label, s.date_creation, s.tms";
  153. $sql.= " FROM ".MAIN_DB_PREFIX."webhook_myobject as s";
  154. //if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  155. $sql.= " WHERE s.entity IN (".getEntity($myobjectstatic->element).")";
  156. //if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  157. //if ($socid) $sql.= " AND s.rowid = $socid";
  158. $sql .= " ORDER BY s.tms DESC";
  159. $sql .= $db->plimit($max, 0);
  160. $resql = $db->query($sql);
  161. if ($resql)
  162. {
  163. $num = $db->num_rows($resql);
  164. $i = 0;
  165. print '<table class="noborder centpercent">';
  166. print '<tr class="liste_titre">';
  167. print '<th colspan="2">';
  168. print $langs->trans("BoxTitleLatestModifiedMyObjects", $max);
  169. print '</th>';
  170. print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
  171. print '</tr>';
  172. if ($num)
  173. {
  174. while ($i < $num)
  175. {
  176. $objp = $db->fetch_object($resql);
  177. $myobjectstatic->id=$objp->rowid;
  178. $myobjectstatic->ref=$objp->ref;
  179. $myobjectstatic->label=$objp->label;
  180. $myobjectstatic->status = $objp->status;
  181. print '<tr class="oddeven">';
  182. print '<td class="nowrap">'.$myobjectstatic->getNomUrl(1).'</td>';
  183. print '<td class="right nowrap">';
  184. print "</td>";
  185. print '<td class="right nowrap">'.dol_print_date($db->jdate($objp->tms), 'day')."</td>";
  186. print '</tr>';
  187. $i++;
  188. }
  189. $db->free($resql);
  190. } else {
  191. print '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
  192. }
  193. print "</table><br>";
  194. }
  195. }
  196. */
  197. print '</div></div>';
  198. // End of page
  199. llxFooter();
  200. $db->close();