dolibarr 21.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 *
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
27// Load Dolibarr environment
28$res = 0;
29// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
30if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
31 $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
32}
33// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
34$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME'];
35$tmp2 = realpath(__FILE__);
36$i = strlen($tmp) - 1;
37$j = strlen($tmp2) - 1;
38while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
39 $i--;
40 $j--;
41}
42if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
43 $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
44}
45if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
46 $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
47}
48// Try main.inc.php using relative path
49if (!$res && file_exists("../main.inc.php")) {
50 $res = @include "../main.inc.php";
51}
52if (!$res && file_exists("../../main.inc.php")) {
53 $res = @include "../../main.inc.php";
54}
55if (!$res && file_exists("../../../main.inc.php")) {
56 $res = @include "../../../main.inc.php";
57}
58if (!$res) {
59 die("Include of main fails");
60}
61
62require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
63
64// Load translation files required by the page
65$langs->loadLangs(array("mymodule@mymodule"));
66
67$action = GETPOST('action', 'aZ09');
68
69$now = dol_now();
70$max = getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5);
71
72// Security check - Protection if external user
73$socid = GETPOSTINT('socid');
74if (isset($user->socid) && $user->socid > 0) {
75 $action = '';
76 $socid = $user->socid;
77}
78
79// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
80//$hookmanager->initHooks(array($object->element.'index'));
81
82// Security check (enable the most restrictive one)
83//if ($user->socid > 0) accessforbidden();
84//if ($user->socid > 0) $socid = $user->socid;
85//if (!isModEnabled('mymodule')) {
86// accessforbidden('Module not enabled');
87//}
88//if (! $user->hasRight('mymodule', 'myobject', 'read')) {
89// accessforbidden();
90//}
91//restrictedArea($user, 'mymodule', 0, 'mymodule_myobject', 'myobject', '', 'rowid');
92//if (empty($user->admin)) {
93// accessforbidden('Must be admin');
94//}
95
96
97/*
98 * Actions
99 */
100
101// None
102
103
104/*
105 * View
106 */
107
108$form = new Form($db);
109$formfile = new FormFile($db);
110
111llxHeader("", $langs->trans("MyModuleArea"), '', '', 0, 0, '', '', '', 'mod-mymodule page-index');
112
113print load_fiche_titre($langs->trans("MyModuleArea"), '', 'mymodule.png@mymodule');
114
115print '<div class="fichecenter"><div class="fichethirdleft">';
116
117
118/* BEGIN MODULEBUILDER DRAFT MYOBJECT
119// Draft MyObject
120if (isModEnabled('mymodule') && $user->hasRight('mymodule', 'read')) {
121 $langs->load("orders");
122
123 $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";
124 $sql.= ", s.code_client";
125 $sql.= " FROM ".MAIN_DB_PREFIX."commande as c";
126 $sql.= ", ".MAIN_DB_PREFIX."societe as s";
127 $sql.= " WHERE c.fk_soc = s.rowid";
128 $sql.= " AND c.fk_statut = 0";
129 $sql.= " AND c.entity IN (".getEntity('commande').")";
130 if ($socid) $sql.= " AND c.fk_soc = ".((int) $socid);
131
132 $resql = $db->query($sql);
133 if ($resql)
134 {
135 $total = 0;
136 $num = $db->num_rows($resql);
137
138 print '<table class="noborder centpercent">';
139 print '<tr class="liste_titre">';
140 print '<th colspan="3">'.$langs->trans("DraftMyObjects").($num?'<span class="badge marginleftonlyshort">'.$num.'</span>':'').'</th></tr>';
141
142 $var = true;
143 if ($num > 0)
144 {
145 $i = 0;
146 while ($i < $num)
147 {
148
149 $obj = $db->fetch_object($resql);
150 print '<tr class="oddeven"><td class="nowrap">';
151
152 $myobjectstatic->id=$obj->rowid;
153 $myobjectstatic->ref=$obj->ref;
154 $myobjectstatic->ref_client=$obj->ref_client;
155 $myobjectstatic->total_ht = $obj->total_ht;
156 $myobjectstatic->total_tva = $obj->total_tva;
157 $myobjectstatic->total_ttc = $obj->total_ttc;
158
159 print $myobjectstatic->getNomUrl(1);
160 print '</td>';
161 print '<td class="nowrap">';
162 print '</td>';
163 print '<td class="right" class="nowrap">'.price($obj->total_ttc).'</td></tr>';
164 $i++;
165 $total += $obj->total_ttc;
166 }
167 if ($total>0)
168 {
169
170 print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td colspan="2" class="right">'.price($total)."</td></tr>";
171 }
172 }
173 else
174 {
175
176 print '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("NoOrder").'</td></tr>';
177 }
178 print "</table><br>";
179
180 $db->free($resql);
181 }
182 else
183 {
184 dol_print_error($db);
185 }
186}
187END MODULEBUILDER DRAFT MYOBJECT */
188
189
190print '</div><div class="fichetwothirdright">';
191
192
193/* BEGIN MODULEBUILDER LASTMODIFIED MYOBJECT
194// Last modified myobject
195if (isModEnabled('mymodule') && $user->hasRight('mymodule', 'read')) {
196 $sql = "SELECT s.rowid, s.ref, s.label, s.date_creation, s.tms";
197 $sql.= " FROM ".MAIN_DB_PREFIX."mymodule_myobject as s";
198 $sql.= " WHERE s.entity IN (".getEntity($myobjectstatic->element).")";
199 //if ($socid) $sql.= " AND s.rowid = $socid";
200 $sql .= " ORDER BY s.tms DESC";
201 $sql .= $db->plimit($max, 0);
202
203 $resql = $db->query($sql);
204 if ($resql)
205 {
206 $num = $db->num_rows($resql);
207 $i = 0;
208
209 print '<table class="noborder centpercent">';
210 print '<tr class="liste_titre">';
211 print '<th colspan="2">';
212 print $langs->trans("BoxTitleLatestModifiedMyObjects", $max);
213 print '</th>';
214 print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
215 print '</tr>';
216 if ($num)
217 {
218 while ($i < $num)
219 {
220 $objp = $db->fetch_object($resql);
221
222 $myobjectstatic->id=$objp->rowid;
223 $myobjectstatic->ref=$objp->ref;
224 $myobjectstatic->label=$objp->label;
225 $myobjectstatic->status = $objp->status;
226
227 print '<tr class="oddeven">';
228 print '<td class="nowrap">'.$myobjectstatic->getNomUrl(1).'</td>';
229 print '<td class="right nowrap">';
230 print "</td>";
231 print '<td class="right nowrap">'.dol_print_date($db->jdate($objp->tms), 'day')."</td>";
232 print '</tr>';
233 $i++;
234 }
235
236 $db->free($resql);
237 } else {
238 print '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
239 }
240 print "</table><br>";
241 }
242}
243*/
244
245print '</div></div>';
246
247// End of page
248llxFooter();
249$db->close();
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:70
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_now($mode='auto')
Return date for now.
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.