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