dolibarr  19.0.0-dev
test_forms.php
1 <?php
2 define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
3 //define("NOLOGIN",1); // This means this output page does not require to be logged.
4 /*if (!defined('NOSESSION')) {
5  define('NOSESSION', '1');
6 }*/
7 
8 // Load Dolibarr environment
9 require '../../main.inc.php';
10 include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
11 
12 // Security
13 if ($dolibarr_main_prod) {
14  accessforbidden('Access forbidden when $dolibarr_main_prod is set to 1');
15 }
16 
17 
18 /*
19  * View
20  */
21 
22 llxHeader();
23 
24 ?>
25 
26 <h2>
27 This page is a sample of page using Dolibarr HTML widget methods. It is designed to make test with<br>
28 - css (add parameter &amp;theme=newtheme to test another theme or edit css of current theme)<br>
29 - 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>
30 - no javascript / usage for bind people (add parameter <a class="wordbreak" href="<?php echo $_SERVER["PHP_SELF"].'?nojs=1'; ?>">nojs=1</a> to force disable javascript)<br>
31 - 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>
32 </h2>
33 <br>
34 
35 <!-- Output to test html.form.class.php -->
36 <?php
37 $form = new Form($db);
38 
39 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
40 
41 // Test1: form->selectDate using tzuser date
42 print "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.";
43 $offsettz = (empty($_SESSION['dol_tz']) ? 0 : $_SESSION['dol_tz']) * 60 * 60;
44 $offsetdst = (empty($_SESSION['dol_dst']) ? 0 : $_SESSION['dol_dst']) * 60 * 60;
45 print " (dol_tz=".$offsettz." dol_dst=".$offsetdst.")<br>\n";
46 print $form->selectDate(dol_now(), 'test1a', 1, 1, 0);
47 
48 print '<br><br>'."\n";
49 
50 print "Test 1b: We must have here current date with hours to 00:00.<br>";
51 print $form->selectDate('', 'test1b', 1, 1, 0);
52 
53 print '<br><br>'."\n";
54 
55 // Test2: form->selectDate using tzuser date
56 print "Test 2: We must have here 1970-01-01 00:00:00 selected (fields can be empty)<br>\n";
57 print $form->selectDate(dol_get_first_day(1970, 1, false), 'test2', 1, 1, 1);
58 
59 print '<br><br>'."\n";
60 
61 // Test3: form->selectDate for 1970-01-01 00:00:00
62 print "Test 3: We must have here 1970-01-01 00:00:00 selected (fields are mandatory)<br>\n";
63 print $form->selectDate(dol_get_first_day(1970, 1, false), 'test3', 1, 1, 0);
64 
65 print '<br><br>'."\n";
66 
67 // Test4a: a select
68 print "Test 4a: a select<br>\n";
69 $array = array(1=>'Value 1', 2=>'Value 2', 3=>'Value 3 ith a very long text. aze eazeae e ae aeae a e a ea ea ea e a e aea e ae aeaeaeaze.');
70 $selected = 3;
71 print $form->selectarray('testselecta', $array, $selected, 1, 0, 0, '', 0, 0, 0, '', 'minwidth100', 1);
72 print '<br><br>';
73 print "Test 4b: a select<br>\n";
74 $array = array(1=>'Value 1', 2=>'Value 2', 3=>'Value 3');
75 $selected = 3;
76 print $form->selectarray('testselectb', $array, $selected, 1, 0, 0, '', 0, 0, 0, '', 'minwidth100', 1);
77 print '<br><br>'."\n";
78 print "Test 4c: Select array with addjscombo not forced<br>\n";
79 $array = array(1=>'Value 1', 2=>'Value 2', 3=>'Value 3');
80 print $form->selectarray('selectarray', $array, $selected, 1, 0, 0, '', 0, 0, 0, '', 'minwidth100', 0);
81 
82 print '<br><br>'."\n";
83 
84 print "Test 4d: a select with ajax refresh and with onchange call of url<br>\n";
85 $selected = -1;
86 print $form->selectArrayAjax('testselectc', DOL_URL_ROOT.'/core/ajax/selectsearchbox.php', $selected, '', '', 0, 1, 'minwidth100', 1);
87 
88 print '<br><br>'."\n";
89 
90 // Test5a: form->select_thirdparty
91 print "Test 5a: Select thirdparty<br>\n";
92 print $form->select_company(0, 'thirdpartytest', '', '', 0, 0, null, 0, 'minwidth100');
93 
94 print '<br><br>'."\n";
95 
96 // Test5b: form->select_product
97 print "Test 5b: Select product (using ajax)<br>\n";
98 $form->select_produits(0, 'producttest', '', 20, 0, 1, 2, '', 0, null, 0, '1', 0, 'minwidth100');
99 
100 print '<br><br>'."\n";
101 
102 // Test5c: a multiselect
103 print "Test 5c: a multiselect<br>\n";
104 $array = array(1=>'Value 1', 2=>'Value 2', 3=>'Value 3');
105 $arrayselected = array(1, 3);
106 print $form->multiselectarray('testmulti', $array, $arrayselected, '', 0, 'minwidth100');
107 
108 print '<br><br>'."\n";
109 
110 // Test6a: Upload of big files
111 print "Test 6a: Upload of big files<br>\n";
112 print "The file will be uploaded in the directory: documents/test/temp/<br>\n";
113 
114 if (is_file(DOL_DOCUMENT_ROOT.'/includes/flowjs/flow.js')) {
115  print '<button id="buttonbigupload" type="button">Browse...</button>';
116  print '&nbsp;<span id="filespan">No file selected.</span>';
117  print '<br><div class="progress-bar filepgbar taligncenter" role="progressbar" style="width:1%;display:none"><span class="small valigntop">0%</span></div>';
118  print '<br><button type="button" style="display:none;" data-fileidentifier="" class="btn green-haze btn-circle cancelfileinput" id="filecancel">Cancel</button>';
119  print '<script src="'.DOL_URL_ROOT.'/includes/flowjs/flow.js"></script>';
120  print '<script>
121  jQuery(document).ready(function() {
122  var flow = new Flow({
123  target:"'.DOL_URL_ROOT.'/core/ajax/flowjs-server.php",
124  query:{module:"test", token:"'.newToken().'"},
125  testChunks:false
126  });
127  ';
128  print 'if(flow.support){
129  flow.assignBrowse(document.getElementById("buttonbigupload"));
130  flow.on("fileAdded", function(file, event){
131  console.log("Trigger event file added", file, event);
132  $("#filespan").text(file.name);
133  $("#filecancel").data("fileidentifier", file.uniqueIdentifier)
134  $("#filecancel").show()
135  $(".filepgbar").show();
136  $(".filepgbar").attr("id",file.uniqueIdentifier+"pgbar")
137  });
138  flow.on("filesSubmitted", function(array,message){
139  console.log("Trigger event file submitted");
140  flow.upload()
141  });
142  flow.on("progress", function(){
143  console.log("progress",flow.files);
144  flow.files.forEach(function(element){
145  console.log(element.progress());
146  width = Math.round(element.progress()*100)
147  width = width.toString()
148  $("#"+element.uniqueIdentifier+"pgbar").width(width+"%")
149  $("#"+element.uniqueIdentifier+"pgbar").children("span").text(width+"%")
150  });
151  });
152  flow.on("fileSuccess", function(file,message){
153  console.log("The file has been uploaded successfully",file,message);
154  });
155  $(".cancelfileinput").on("click", function(){
156  filename = $(this).data("fileidentifier");
157  file = flow.getFromUniqueIdentifier(filename);
158  file.cancel();
159  $("#"+file.uniqueIdentifier+"pgbar").hide();
160  console.log("We remove file "+filename);
161  $("#filespan").text("No file selected.");
162  $(this).hide();
163  })
164  flow.on("fileError", function(file, message){
165  console.log("Error on file upload",file, message);
166  $("#"+file.uniqueIdentifier+"pgbar").width(20+"%");
167  $("#"+file.uniqueIdentifier+"pgbar").children("span").text("ERROR UPLOAD");
168  });
169  }
170  })
171  ';
172  print '</script>';
173 } else {
174  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";
175 }
176 
177 print '</div>';
178 
179 // End of page
180 llxFooter();
181 $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 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
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:576
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:93
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.