dolibarr 21.0.0-beta
test_forms.php
1<?php
2/* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
18//define("NOLOGIN",1); // This means this output page does not require to be logged.
19/*if (!defined('NOSESSION')) {
20 define('NOSESSION', '1');
21}*/
22
23// Load Dolibarr environment
24require '../../main.inc.php';
25require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
26
27// Security
28if ($dolibarr_main_prod) {
29 accessforbidden('Access forbidden when $dolibarr_main_prod is set to 1');
30}
31
32
33/*
34 * View
35 */
36
37llxHeader();
38
39?>
40
41This page is a sample of page using Dolibarr HTML widget methods. It is designed to make test with<br>
42- css (add parameter &amp;theme=newtheme to test another theme or edit css of current theme)<br>
43- jmobile (add parameter <a class="wordbreak" href="<?php echo $_SERVER["PHP_SELF"].'?dol_use_jmobile=1&dol_optimize_smallscreen=1'; ?>">dol_use_jmobile=1&amp;dol_optimize_smallscreen=1</a> and switch to small screen < 570 to enable with emulated jmobile)<br>
44- no javascript / usage for blind people (add parameter <a class="wordbreak" href="<?php echo $_SERVER["PHP_SELF"].'?nojs=1'; ?>">nojs=1</a> to force disable javascript)<br>
45- use with a text browser (add parameter <a class="wordbreak" href="<?php echo $_SERVER["PHP_SELF"].'?textbrowser=1'; ?>">textbrowser=1</a> to force detection of a text browser)<br>
46<br><br>
47
48<!-- Output to test html.form.class.php -->
49<?php
50$form = new Form($db);
51
52print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
53
54// Test1: form->selectDate using tzuser date
55print "Test 1a: We must have here current date and hour for user (must match hour on browser). Note: Check your are logged so user TZ and DST are known.";
56$offsettz = (empty($_SESSION['dol_tz']) ? 0 : $_SESSION['dol_tz']) * 60 * 60;
57$offsetdst = (empty($_SESSION['dol_dst']) ? 0 : $_SESSION['dol_dst']) * 60 * 60;
58print " (dol_tz=".$offsettz." dol_dst=".$offsetdst.")<br>\n";
59print $form->selectDate(dol_now(), 'test1a', 1, 1, 0);
60
61print '<br><br>'."\n";
62
63print "Test 1b: We must have here current date with hours to 00:00.<br>";
64print $form->selectDate('', 'test1b', 1, 1, 0);
65
66print '<br><br>'."\n";
67
68// Test2: form->selectDate using tzuser date
69print "Test 2: We must have here 1970-01-01 selected (fields can be empty)<br>\n";
70print $form->selectDate(dol_get_first_day(1970, 1, false), 'test2', 1, 1, 1);
71
72print '<br><br>'."\n";
73
74// Test3: form->selectDate for 1970-01-01 00:00:00
75print "Test 3: We must have here 1970-01-01 00:00:00 selected (fields are mandatory)<br>\n";
76print $form->selectDate(dol_get_first_day(1970, 1, false), 'test3', 1, 1, 0);
77
78print '<br><br>'."\n";
79
80// Test4a: a select
81print "Test 4a: a select<br>\n";
82$array = array(1=>'Value 1', 2=>'Value 2', 3=>'Value 3 with a very long text. aze eazeae e ae aeae a e a ea ea ea e a e aea e ae aeaeaeaze.');
83$selected = 3;
84print $form->selectarray('testselecta', $array, $selected, 1, 0, 0, '', 0, 0, 0, '', 'minwidth100', 1);
85print '<br><br>';
86print "Test 4b: a select<br>\n";
87$array = array(1=>'Value 1', 2=>'Value 2', 3=>'Value 3');
88$selected = 3;
89print $form->selectarray('testselectb', $array, $selected, 1, 0, 0, '', 0, 0, 0, '', 'minwidth100', 1);
90print '<br><br>'."\n";
91print "Test 4c: Select array with addjscombo not forced<br>\n";
92$array = array(1=>'Value 1', 2=>'Value 2', 3=>'Value 3');
93print $form->selectarray('selectarray', $array, $selected, 1, 0, 0, '', 0, 0, 0, '', 'minwidth100', 0);
94
95print '<br><br>'."\n";
96
97print "Test 4d: a select with ajax refresh and with onchange call of url<br>\n";
98$selected = -1;
99print $form->selectArrayAjax('testselectc', DOL_URL_ROOT.'/core/ajax/selectsearchbox.php', $selected, '', '', 0, 1, 'minwidth100', 1);
100
101print '<br><br>'."\n";
102
103// Test5a: form->select_thirdparty
104print "Test 5a: Select thirdparty<br>\n";
105print $form->select_company(0, 'thirdpartytest', '', '', 0, 0, null, 0, 'minwidth100');
106
107print '<br><br>'."\n";
108
109// Test5b: form->select_product
110print "Test 5b: Select product (using ajax)<br>\n";
111$form->select_produits(0, 'producttest', '', 20, 0, 1, 2, '', 0, null, 0, '1', 0, 'minwidth100');
112
113print '<br><br>'."\n";
114
115// Test5c: a multiselect
116print "Test 5c: a multiselect<br>\n";
117$array = array(1=>'Value 1', 2=>'Value 2', 3=>'Value 3');
118$arrayselected = array(1, 3);
119print $form->multiselectarray('testmulti', $array, $arrayselected, '', 0, 'minwidth100');
120
121print '<br><br>'."\n";
122
123// Test6a: Upload of big files
124print "Test 6a: Upload of big files<br>\n";
125print "The file will be uploaded in the directory: documents/test/temp/<br>\n";
126
127if (is_file(DOL_DOCUMENT_ROOT.'/includes/flowjs/flow.js')) {
128 print '<button id="buttonbigupload" type="button">Browse...</button>';
129 print '&nbsp;<span id="filespan">No file selected.</span>';
130 print '<br><div class="progress-bar filepgbar taligncenter" role="progressbar" style="width:1%;display:none"><span class="small valigntop">0%</span></div>';
131 print '<br><button type="button" style="display:none;" data-fileidentifier="" class="btn green-haze btn-circle cancelfileinput" id="filecancel">Cancel</button>';
132 print '<script src="'.DOL_URL_ROOT.'/includes/flowjs/flow.js"></script>';
133 print '<script>
134 jQuery(document).ready(function() {
135 var flow = new Flow({
136 target:"'.DOL_URL_ROOT.'/core/ajax/flowjs-server.php",
137 query:{module:"test", token:"'.newToken().'"},
138 testChunks:false
139 });
140 ';
141 print 'if(flow.support){
142 flow.assignBrowse(document.getElementById("buttonbigupload"));
143 flow.on("fileAdded", function(file, event){
144 console.log("Trigger event file added", file, event);
145 $("#filespan").text(file.name);
146 $("#filecancel").data("fileidentifier", file.uniqueIdentifier)
147 $("#filecancel").show()
148 $(".filepgbar").show();
149 $(".filepgbar").attr("id",file.uniqueIdentifier+"pgbar")
150 });
151 flow.on("filesSubmitted", function(array,message){
152 console.log("Trigger event file submitted");
153 flow.upload()
154 });
155 flow.on("progress", function(){
156 console.log("progress",flow.files);
157 flow.files.forEach(function(element){
158 console.log(element.progress());
159 width = Math.round(element.progress()*100)
160 width = width.toString()
161 $("#"+element.uniqueIdentifier+"pgbar").width(width+"%")
162 $("#"+element.uniqueIdentifier+"pgbar").children("span").text(width+"%")
163 });
164 });
165 flow.on("fileSuccess", function(file,message){
166 console.log("The file has been uploaded successfully",file,message);
167 });
168 $(".cancelfileinput").on("click", function(){
169 filename = $(this).data("fileidentifier");
170 file = flow.getFromUniqueIdentifier(filename);
171 file.cancel();
172 $("#"+file.uniqueIdentifier+"pgbar").hide();
173 console.log("We remove file "+filename);
174 $("#filespan").text("No file selected.");
175 $(this).hide();
176 })
177 flow.on("fileError", function(file, message){
178 console.log("Error on file upload",file, message);
179 $("#"+file.uniqueIdentifier+"pgbar").width(20+"%");
180 $("#"+file.uniqueIdentifier+"pgbar").children("span").text("ERROR UPLOAD");
181 });
182 }
183 })
184 ';
185 print '</script>';
186} else {
187 print "If this message displays, please add flow.js and flow.min.js files which can be found here: https://github.com/flowjs/flow.js and place the js lib in htdocs/includes/flowjs/<br>\n";
188}
189
190print '</div>';
191
192// End of page
193llxFooter();
194$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:71
Class to manage generation of HTML components Only common components must be here.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition date.lib.php:600
llxFooter()
Footer empty.
Definition document.php:107
dol_now($mode='auto')
Return date for now.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
usage($program, $header)
Print the usage when executing scripts from install/.
Definition inc.php:94
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.