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