dolibarr 25.0.0-alpha
mymoduleindex.php
Go to the documentation of this file.
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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) ---Replace with your own copyright and developer email---
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Load Dolibarr environment
30$res = 0;
31// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
32if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
33 $res = @include str_replace("..", "", $_SERVER["CONTEXT_DOCUMENT_ROOT"])."/main.inc.php";
34}
35// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
36$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME'];
37$tmp2 = realpath(__FILE__);
38$i = strlen($tmp) - 1; // @phan-suppress-current-line DolibarrForbiddenFunctionPlugin
39$j = strlen($tmp2) - 1; // @phan-suppress-current-line DolibarrForbiddenFunctionPlugin
40while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
41 $i--;
42 $j--;
43}
44if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
45 $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
46}
47if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
48 $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
49}
50// Try main.inc.php using relative path
51if (!$res && file_exists("../main.inc.php")) {
52 $res = @include "../main.inc.php";
53}
54if (!$res && file_exists("../../main.inc.php")) {
55 $res = @include "../../main.inc.php";
56}
57if (!$res && file_exists("../../../main.inc.php")) {
58 $res = @include "../../../main.inc.php";
59}
60if (!$res) {
61 die("Include of main fails");
62}
71require_once DOL_DOCUMENT_ROOT . '/core/lib/functions.lib.php';
72include_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
73
74// Load translation files required by the page
75$langs->loadLangs(array("mymodule@mymodule"));
76
77$action = GETPOST('action', 'aZ09');
78
79$now = dol_now();
80
81$max = getDolUserInt('MAIN_SIZE_SHORTLIST_LIMIT', getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5));
82
83// Security check - Protection if external user
84$socid = GETPOSTINT('socid');
85if (!empty($user->socid) && $user->socid > 0) {
86 $action = '';
87 $socid = $user->socid;
88}
89
90// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
91//$hookmanager->initHooks(array($object->element.'index'));
92
93// Security check (enable the most restrictive one)
94//if ($user->socid > 0) accessforbidden();
95//if ($user->socid > 0) $socid = $user->socid;
96//if (!isModEnabled('mymodule')) {
97// accessforbidden('Module not enabled');
98//}
99//if (! $user->hasRight('mymodule', 'myobject', 'read')) {
100// accessforbidden();
101//}
102//restrictedArea($user, 'mymodule', 0, 'mymodule_myobject', 'myobject', '', 'rowid');
103//if (empty($user->admin)) {
104// accessforbidden('Must be admin');
105//}
106
107
108/*
109 * Actions
110 */
111
112// None
113
114
115/*
116 * View
117 */
118
119$form = new Form($db);
120$formfile = new FormFile($db);
121
122llxHeader("", $langs->trans("MyModuleArea"), '', '', 0, 0, '', '', '', 'mod-mymodule page-index');
123
124print load_fiche_titre($langs->trans("MyModuleArea"), '', 'mymodule.png@mymodule');
125
126print '<div class="fichecenter"><div class="fichethirdleft">';
127
128
129/* BEGIN MODULEBUILDER DRAFT MYOBJECT
130// Draft MyObject
131if (isModEnabled('mymodule') && $user->hasRight('mymodule', 'read')) {
132 $langs->load("orders");
133
134 $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";
135 $sql.= ", s.code_client";
136 $sql.= " FROM ".$db->prefix()."commande as c";
137 $sql.= ", ".$db->prefix()."societe as s";
138 $sql.= " WHERE c.fk_soc = s.rowid";
139 $sql.= " AND c.fk_statut = 0";
140 $sql.= " AND c.entity IN (".getEntity('commande').")";
141 if ($socid) $sql.= " AND c.fk_soc = ".((int) $socid);
142
143 $resql = $db->query($sql);
144 if ($resql)
145 {
146 $total = 0;
147 $num = $db->num_rows($resql);
148
149 print '<table class="noborder centpercent">';
150 print '<tr class="liste_titre">';
151 print '<th colspan="3">'.$langs->trans("DraftMyObjects").($num?'<span class="badge marginleftonlyshort">'.$num.'</span>':'').'</th></tr>';
152
153 $var = true;
154 if ($num > 0)
155 {
156 $i = 0;
157 while ($i < $num)
158 {
159
160 $obj = $db->fetch_object($resql);
161 print '<tr class="oddeven"><td class="nowrap">';
162
163 $myobjectstatic->id=$obj->rowid;
164 $myobjectstatic->ref=$obj->ref;
165 $myobjectstatic->ref_client=$obj->ref_client;
166 $myobjectstatic->total_ht = $obj->total_ht;
167 $myobjectstatic->total_tva = $obj->total_tva;
168 $myobjectstatic->total_ttc = $obj->total_ttc;
169
170 print $myobjectstatic->getNomUrl(1);
171 print '</td>';
172 print '<td class="nowrap">';
173 print '</td>';
174 print '<td class="right" class="nowrap">'.price($obj->total_ttc).'</td></tr>';
175 $i++;
176 $total += $obj->total_ttc;
177 }
178 if ($total>0)
179 {
180
181 print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td colspan="2" class="right">'.price($total)."</td></tr>";
182 }
183 }
184 else
185 {
186
187 print '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("NoOrder").'</td></tr>';
188 }
189 print "</table><br>";
190
191 $db->free($resql);
192 }
193 else
194 {
195 dol_print_error($db);
196 }
197}
198END MODULEBUILDER DRAFT MYOBJECT */
199
200
201print '</div><div class="fichetwothirdright">';
202
203
204/* BEGIN MODULEBUILDER LASTMODIFIED MYOBJECT
205// Last modified myobject
206if (isModEnabled('mymodule') && $user->hasRight('mymodule', 'read')) {
207 $sql = "SELECT s.rowid, s.ref, s.label, s.date_creation, s.tms";
208 $sql.= " FROM ".$db->prefix()."mymodule_myobject as s";
209 $sql.= " WHERE s.entity IN (".getEntity($myobjectstatic->element).")";
210 //if ($socid) $sql.= " AND s.rowid = $socid";
211 $sql .= " ORDER BY s.tms DESC";
212 $sql .= $db->plimit($max, 0);
213
214 $resql = $db->query($sql);
215 if ($resql)
216 {
217 $num = $db->num_rows($resql);
218 $i = 0;
219
220 print '<table class="noborder centpercent">';
221 print '<tr class="liste_titre">';
222 print '<th colspan="2">';
223 print $langs->trans("BoxTitleLatestModifiedMyObjects", $max);
224 print '</th>';
225 print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
226 print '</tr>';
227 if ($num)
228 {
229 while ($i < $num)
230 {
231 $objp = $db->fetch_object($resql);
232
233 $myobjectstatic->id=$objp->rowid;
234 $myobjectstatic->ref=$objp->ref;
235 $myobjectstatic->label=$objp->label;
236 $myobjectstatic->status = $objp->status;
237
238 print '<tr class="oddeven">';
239 print '<td class="nowrap">'.$myobjectstatic->getNomUrl(1).'</td>';
240 print '<td class="right nowrap">';
241 print "</td>";
242 print '<td class="right nowrap">'.dol_print_date($db->jdate($objp->tms), 'day')."</td>";
243 print '</tr>';
244 $i++;
245 }
246
247 $db->free($resql);
248 } else {
249 print '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
250 }
251 print "</table><br>";
252 }
253}
254*/
255
256print '</div></div>';
257
258// End of page
259llxFooter();
260$db->close();
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
dol_now($mode='gmt')
Return date for now.
getDolUserInt($key, $default=0, $tmpuser=null)
Return Dolibarr user constant int value.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.