dolibarr 24.0.0-beta
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;
39$j = strlen($tmp2) - 1;
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}
71include_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
72
73// Load translation files required by the page
74$langs->loadLangs(array("mymodule@mymodule"));
75
76$action = GETPOST('action', 'aZ09');
77
78$now = dol_now();
79$max = getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5);
80
81// Security check - Protection if external user
82$socid = GETPOSTINT('socid');
83if (!empty($user->socid) && $user->socid > 0) {
84 $action = '';
85 $socid = $user->socid;
86}
87
88// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
89//$hookmanager->initHooks(array($object->element.'index'));
90
91// Security check (enable the most restrictive one)
92//if ($user->socid > 0) accessforbidden();
93//if ($user->socid > 0) $socid = $user->socid;
94//if (!isModEnabled('mymodule')) {
95// accessforbidden('Module not enabled');
96//}
97//if (! $user->hasRight('mymodule', 'myobject', 'read')) {
98// accessforbidden();
99//}
100//restrictedArea($user, 'mymodule', 0, 'mymodule_myobject', 'myobject', '', 'rowid');
101//if (empty($user->admin)) {
102// accessforbidden('Must be admin');
103//}
104
105
106/*
107 * Actions
108 */
109
110// None
111
112
113/*
114 * View
115 */
116
117$form = new Form($db);
118$formfile = new FormFile($db);
119
120llxHeader("", $langs->trans("MyModuleArea"), '', '', 0, 0, '', '', '', 'mod-mymodule page-index');
121
122print load_fiche_titre($langs->trans("MyModuleArea"), '', 'mymodule.png@mymodule');
123
124print '<div class="fichecenter"><div class="fichethirdleft">';
125
126
127/* BEGIN MODULEBUILDER DRAFT MYOBJECT
128// Draft MyObject
129if (isModEnabled('mymodule') && $user->hasRight('mymodule', 'read')) {
130 $langs->load("orders");
131
132 $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";
133 $sql.= ", s.code_client";
134 $sql.= " FROM ".$db->prefix()."commande as c";
135 $sql.= ", ".$db->prefix()."societe as s";
136 $sql.= " WHERE c.fk_soc = s.rowid";
137 $sql.= " AND c.fk_statut = 0";
138 $sql.= " AND c.entity IN (".getEntity('commande').")";
139 if ($socid) $sql.= " AND c.fk_soc = ".((int) $socid);
140
141 $resql = $db->query($sql);
142 if ($resql)
143 {
144 $total = 0;
145 $num = $db->num_rows($resql);
146
147 print '<table class="noborder centpercent">';
148 print '<tr class="liste_titre">';
149 print '<th colspan="3">'.$langs->trans("DraftMyObjects").($num?'<span class="badge marginleftonlyshort">'.$num.'</span>':'').'</th></tr>';
150
151 $var = true;
152 if ($num > 0)
153 {
154 $i = 0;
155 while ($i < $num)
156 {
157
158 $obj = $db->fetch_object($resql);
159 print '<tr class="oddeven"><td class="nowrap">';
160
161 $myobjectstatic->id=$obj->rowid;
162 $myobjectstatic->ref=$obj->ref;
163 $myobjectstatic->ref_client=$obj->ref_client;
164 $myobjectstatic->total_ht = $obj->total_ht;
165 $myobjectstatic->total_tva = $obj->total_tva;
166 $myobjectstatic->total_ttc = $obj->total_ttc;
167
168 print $myobjectstatic->getNomUrl(1);
169 print '</td>';
170 print '<td class="nowrap">';
171 print '</td>';
172 print '<td class="right" class="nowrap">'.price($obj->total_ttc).'</td></tr>';
173 $i++;
174 $total += $obj->total_ttc;
175 }
176 if ($total>0)
177 {
178
179 print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td colspan="2" class="right">'.price($total)."</td></tr>";
180 }
181 }
182 else
183 {
184
185 print '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("NoOrder").'</td></tr>';
186 }
187 print "</table><br>";
188
189 $db->free($resql);
190 }
191 else
192 {
193 dol_print_error($db);
194 }
195}
196END MODULEBUILDER DRAFT MYOBJECT */
197
198
199print '</div><div class="fichetwothirdright">';
200
201
202/* BEGIN MODULEBUILDER LASTMODIFIED MYOBJECT
203// Last modified myobject
204if (isModEnabled('mymodule') && $user->hasRight('mymodule', 'read')) {
205 $sql = "SELECT s.rowid, s.ref, s.label, s.date_creation, s.tms";
206 $sql.= " FROM ".$db->prefix()."mymodule_myobject as s";
207 $sql.= " WHERE s.entity IN (".getEntity($myobjectstatic->element).")";
208 //if ($socid) $sql.= " AND s.rowid = $socid";
209 $sql .= " ORDER BY s.tms DESC";
210 $sql .= $db->plimit($max, 0);
211
212 $resql = $db->query($sql);
213 if ($resql)
214 {
215 $num = $db->num_rows($resql);
216 $i = 0;
217
218 print '<table class="noborder centpercent">';
219 print '<tr class="liste_titre">';
220 print '<th colspan="2">';
221 print $langs->trans("BoxTitleLatestModifiedMyObjects", $max);
222 print '</th>';
223 print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
224 print '</tr>';
225 if ($num)
226 {
227 while ($i < $num)
228 {
229 $objp = $db->fetch_object($resql);
230
231 $myobjectstatic->id=$objp->rowid;
232 $myobjectstatic->ref=$objp->ref;
233 $myobjectstatic->label=$objp->label;
234 $myobjectstatic->status = $objp->status;
235
236 print '<tr class="oddeven">';
237 print '<td class="nowrap">'.$myobjectstatic->getNomUrl(1).'</td>';
238 print '<td class="right nowrap">';
239 print "</td>";
240 print '<td class="right nowrap">'.dol_print_date($db->jdate($objp->tms), 'day')."</td>";
241 print '</tr>';
242 $i++;
243 }
244
245 $db->free($resql);
246 } else {
247 print '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
248 }
249 print "</table><br>";
250 }
251}
252*/
253
254print '</div></div>';
255
256// End of page
257llxFooter();
258$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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_now($mode='gmt')
Return date for now.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.