test_forms.php 7.1 KB

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