From 53f3e4688b2d42661199ceed9ffcc519c5b2b963 Mon Sep 17 00:00:00 2001 From: Tim Schofield Date: Sat, 27 Oct 2018 22:00:13 +0100 Subject: [PATCH] Use the gettext function on string to enable translation (#106) Files changed in commit: FormDesigner.php On branch master --- FormDesigner.php | 269 +++++++++++++++++++++-------------------------- 1 file changed, 117 insertions(+), 152 deletions(-) diff --git a/FormDesigner.php b/FormDesigner.php index 4f63d192d..e4ad0ab2f 100644 --- a/FormDesigner.php +++ b/FormDesigner.php @@ -17,60 +17,46 @@ /* RCHACON: To Do: standardize the name of the parameters x, y, width, height, font-size, alignment and radius inside the xml files. Non-standard attribute "Length" should be replace with "width". */ /* RCHACON: Question: The use or not of for usability ? */ - -include('includes/session.php'); +include ('includes/session.php'); $Title = _('Form Designer'); $ViewTopic = 'Setup'; $BookMark = 'FormDesigner'; -include('includes/header.php'); +include ('includes/header.php'); -echo '

', // Icon title. - _('Form Designer'), '

'; // Page title. +echo '

', // Icon title. +_('Form Designer'), '

'; // Page title. // BEGIN: Functions division --------------------------------------------------- function InputX($keyName, $keyValue) { - // Function to input the X coordinate from the left side of the sheet to the left side of the field in points (72 points = 25,4 mm). - echo '', - ''; + // Function to input the X coordinate from the left side of the sheet to the left side of the field in points (72 points = 25,4 mm). + echo '', ''; } function InputY($keyName, $keyValue) { - // Function to input the Y coordinate from the lower side of the sheet to the top side of the field in points (72 points = 25,4 mm). - echo '', - ''; + // Function to input the Y coordinate from the lower side of the sheet to the top side of the field in points (72 points = 25,4 mm). + echo '', ''; } function InputLength($keyName, $keyValue) { - // Function to input the the Length of the field in points (72 points = 25,4 mm). - echo '', - ''; - // Requires to standardize xml files from "Length" to "Width" before changing the xml name.********** + // Function to input the the Length of the field in points (72 points = 25,4 mm). + echo '', ''; + // Requires to standardize xml files from "Length" to "Width" before changing the xml name.********** + } function InputWidth($keyName, $keyValue) { - // Function to input the the width of the field in points (72 points = 25,4 mm). - echo '', - ''; - // Requires to standardize xml files from "width" to "Width" before changing the xml name.********** + // Function to input the the width of the field in points (72 points = 25,4 mm). + echo '', ''; + // Requires to standardize xml files from "width" to "Width" before changing the xml name.********** + } function InputHeight($keyName, $keyValue) { - // Function to input the the height of the field in points (72 points = 25,4 mm). - echo '', - ''; - // Requires to standardize xml files from "height" to "Height" before changing the xml name.********** + // Function to input the the height of the field in points (72 points = 25,4 mm). + echo '', ''; + // Requires to standardize xml files from "height" to "Height" before changing the xml name.********** + } function SelectAlignment($keyName, $keyValue) { - // Function to select a text alignment. + // Function to select a text alignment. $Alignments = array(); // Possible alignments $Alignments['left']['Caption'] = _('Left'); $Alignments['left']['Title'] = _('Text lines are rendered flush left'); @@ -80,34 +66,34 @@ function SelectAlignment($keyName, $keyValue) { $Alignments['right']['Title'] = _('Text lines are rendered flush right'); $Alignments['full']['Caption'] = _('Justify'); $Alignments['full']['Title'] = _('Text lines are justified to both margins'); - echo '' . _('Alignment'). ' = '; foreach ($Alignments as $AlignmentValue => $AlignmentOption) { echo '' . $AlignmentOption['Caption'] . ''; + if ($AlignmentValue == $keyValue) { + echo ' selected="selected"'; + } + echo ' title="' . $AlignmentOption['Title'] . '" value="' . $AlignmentValue . '">' . $AlignmentOption['Caption'] . ''; } echo ''; } function InputFontSize($keyName, $keyValue) { - // Function to select a text font size. - echo '', - ''; + // Function to select a text font size. + echo '', ''; } function SelectShowElement($keyName, $keyValue) { - // Function to select to show or not an element. + // Function to select to show or not an element. $Shows = array(); // Possible alignments $Shows['No']['Caption'] = _('No'); $Shows['No']['Title'] = _('Does not display this element'); $Shows['Yes']['Caption'] = _('Yes'); $Shows['Yes']['Title'] = _('Displays this element'); - echo '', - ''; foreach ($Shows as $ShowValue => $ShowOption) { echo '' . $ShowOption['Caption'] . ''; + if ($ShowValue == $keyValue) { + echo ' selected="selected"'; + } + echo ' title="' . $ShowOption['Title'] . '" value="' . $ShowValue . '">' . $ShowOption['Caption'] . ''; } echo ''; } @@ -115,12 +101,7 @@ function SelectShowElement($keyName, $keyValue) { // BEGIN: Data division -------------------------------------------------------- -$PaperSizes = array('A3_Portrait', 'A3_Landscape', - 'A4_Portrait', 'A4_Landscape', - 'A5_Portrait', 'A5_Landscape', - 'A6_Portrait', 'A6_Landscape', - 'Legal_Portrait', 'Legal_Landscape', - 'Letter_Portrait', 'Letter_Landscape'); // Possible paper sizes and orientations. +$PaperSizes = array('A3_Portrait', 'A3_Landscape', 'A4_Portrait', 'A4_Landscape', 'A5_Portrait', 'A5_Landscape', 'A6_Portrait', 'A6_Landscape', 'Legal_Portrait', 'Legal_Landscape', 'Letter_Portrait', 'Letter_Landscape'); // Possible paper sizes and orientations. // END: Data division ---------------------------------------------------------- @@ -129,25 +110,25 @@ function SelectShowElement($keyName, $keyValue) { * save it then we first have to get the POST values into a * simplexml object and then save the file as either a * temporary file, or into the main code - */ +*/ if (isset($_POST['preview']) or isset($_POST['save'])) { /*First create a simple xml object from the main file */ - $FormDesign = simplexml_load_file($PathPrefix.'companies/'.$_SESSION['DatabaseName'].'/FormDesigns/'.$_POST['FormName']); - $FormDesign['name']=$_POST['formname']; - if (mb_substr($_POST['PaperSize'],-8)=='Portrait') { - $_POST['PaperSize']=mb_substr($_POST['PaperSize'],0,mb_strlen($_POST['PaperSize'])-9); + $FormDesign = simplexml_load_file($PathPrefix . 'companies/' . $_SESSION['DatabaseName'] . '/FormDesigns/' . $_POST['FormName']); + $FormDesign['name'] = $_POST['formname']; + if (mb_substr($_POST['PaperSize'], -8) == 'Portrait') { + $_POST['PaperSize'] = mb_substr($_POST['PaperSize'], 0, mb_strlen($_POST['PaperSize']) - 9); } - $FormDesign->PaperSize=$_POST['PaperSize']; - $FormDesign->LineHeight=$_POST['LineHeight']; + $FormDesign->PaperSize = $_POST['PaperSize']; + $FormDesign->LineHeight = $_POST['LineHeight']; /*Iterate through the object filling in the values from the POST variables */ foreach ($FormDesign as $key) { - foreach ($key as $subkey=>$value) { - if ($key['type']=='ElementArray') { - foreach ($value as $subsubkey=>$subvalue) { - $value->$subsubkey = $_POST[$value['id'].$subsubkey]; + foreach ($key as $subkey => $value) { + if ($key['type'] == 'ElementArray') { + foreach ($value as $subsubkey => $subvalue) { + $value->$subsubkey = $_POST[$value['id'] . $subsubkey]; } } else { - $key->$subkey = $_POST[$key['id'].$subkey]; + $key->$subkey = $_POST[$key['id'] . $subkey]; } } } @@ -155,114 +136,104 @@ function SelectShowElement($keyName, $keyValue) { * save it to the temporary directory and call the * PDF creating script */ if (isset($_POST['preview'])) { - $FormDesign->asXML(sys_get_temp_dir().'/'.$_POST['FormName']); + $FormDesign->asXML(sys_get_temp_dir() . '/' . $_POST['FormName']); switch ($_POST['FormName']) { case 'PurchaseOrder.xml': echo ''; - break; + break; case 'GoodsReceived.xml': echo ''; - break; + break; case 'PickingList.xml': echo ''; - break; + break; case 'QALabel.xml': echo ''; - break; + break; case 'WOPaperwork.xml': echo ''; - break; + break; case 'FGLabel.xml': echo ''; - break; + break; case 'ShippingLabel.xml': echo ''; - break; + break; } } else { - /* otherwise check that the web server has write premissions on the companies - * directory and save the xml file to the correct directory */ - if (is_writable($PathPrefix.'companies/'.$_SESSION['DatabaseName'].'/FormDesigns/'.$_POST['FormName'])) { - $FormDesign->asXML($PathPrefix.'companies/'.$_SESSION['DatabaseName'].'/FormDesigns/'.$_POST['FormName']); + /* otherwise check that the web server has write premissions on the companies + * directory and save the xml file to the correct directory */ + if (is_writable($PathPrefix . 'companies/' . $_SESSION['DatabaseName'] . '/FormDesigns/' . $_POST['FormName'])) { + $FormDesign->asXML($PathPrefix . 'companies/' . $_SESSION['DatabaseName'] . '/FormDesigns/' . $_POST['FormName']); } else { - prnMsg( _('The web server does not have write permissions on the file ') . '
' . $PathPrefix.'companies/'.$_SESSION['DatabaseName'].'/FormDesigns/'.$_POST['FormName']. - '
' . _('Your changes cannot be saved') . '
' . _('See your system administrator to correct this problem'), 'error'); + prnMsg(_('The web server does not have write permissions on the file ') . '
' . $PathPrefix . 'companies/' . $_SESSION['DatabaseName'] . '/FormDesigns/' . $_POST['FormName'] . '
' . _('Your changes cannot be saved') . '
' . _('See your system administrator to correct this problem'), 'error'); } } } /* If no form has been selected to edit, then offer a drop down list of possible forms */ if (empty($_POST['FormName'])) { - echo '
+ echo ' - + -
Edit Form Layout', _('Edit Form Layout'), '
', _('Select the form to edit'), ' + echo '
', - '
', - '', // "Submit" button. - '', // "Return" button. - '
+
', '
', '', // "Submit" button. + '', // "Return" button. + '
'; - include('includes/footer.php'); + include ('includes/footer.php'); exit; } // End of if (empty($_POST['FormName'])) - /* If we are not previewing the form then load up the simplexml object from the main xml file */ if (empty($_POST['preview'])) { - $FormDesign = simplexml_load_file($PathPrefix.'companies/'.$_SESSION['DatabaseName'].'/FormDesigns/'.$_POST['FormName']); + $FormDesign = simplexml_load_file($PathPrefix . 'companies/' . $_SESSION['DatabaseName'] . '/FormDesigns/' . $_POST['FormName']); } -echo '
' . - _('Enter the changes that you want in the form layout below.') . '
'. - _('All measurements are in PostScript points (72 points = 25,4 mm).') . '
'. - _('All coordinates are measured from the lower left corner of the sheet to the top left corner of the element.') . '

'; +echo '
' . _('Enter the changes that you want in the form layout below.') . '
' . _('All measurements are in PostScript points (72 points = 25,4 mm).') . '
' . _('All coordinates are measured from the lower left corner of the sheet to the top left corner of the element.') . '

'; -echo '
'; +echo ''; echo '
'; echo ''; -echo ''; +echo ''; echo ' - + ', // Select the paper size/orientation: - ' +'', // Sets the standard line height for the form: - ' +'
', _((string)$FormDesign['name']), '', _((string)$FormDesign['name']), '
+echo '
@@ -292,47 +263,47 @@ function SelectShowElement($keyName, $keyValue) { ', InputY($key['id'], $key->y), ' ', InputWidth($key['id'], $key->width), ' ', InputHeight($key['id'], $key->height), ''; - break; + break; case 'SimpleText': - echo '', _((string)$key['name']), ' + echo '', _((string)$key['name']), ' ', InputX($key['id'], $key->x), ' ', InputY($key['id'], $key->y), ' ', InputFontSize($key['id'], $key->FontSize), ''; - break; + break; case 'MultiLineText': - echo '', _((string)$key['name']), ' + echo '', _((string)$key['name']), ' ', InputX($key['id'], $key->x), ' ', InputY($key['id'], $key->y), ' ', InputLength($key['id'], $key->Length), '', // Non-standard attribute "Length" instead of "width". - '', InputFontSize($key['id'], $key->FontSize), ''; - break; + '', InputFontSize($key['id'], $key->FontSize), ''; + break; case 'ElementArray': echo '' . _((string)$key['name']) . ''; foreach ($key as $subkey) { - echo ''; - if ($subkey['type']=='SimpleText') { + echo ''; + if ($subkey['type'] == 'SimpleText') { echo '' . _((string)$subkey['name']) . ''; InputX($subkey['id'], $subkey->x); InputY($subkey['id'], $subkey->y); InputFontSize($subkey['id'], $subkey->FontSize); - } elseif ($subkey['type']=='MultiLineText') { // This element (9 td) overflows the table size (7 td). + } elseif ($subkey['type'] == 'MultiLineText') { // This element (9 td) overflows the table size (7 td). echo '' . _((string)$subkey['name']) . ''; InputX($subkey['id'], $subkey->x); InputY($subkey['id'], $subkey->y); InputLength($subkey['id'], $subkey->Length); InputFontSize($subkey['id'], $subkey->FontSize); - } elseif ($subkey['type']=='DataText') { + } elseif ($subkey['type'] == 'DataText') { echo '' . _((string)$subkey['name']) . ''; InputX($subkey['id'], $subkey->x); InputLength($subkey['id'], $subkey->Length); InputFontSize($subkey['id'], $subkey->FontSize); - } elseif ($subkey['type']=='StartLine') { + } elseif ($subkey['type'] == 'StartLine') { echo '' . _((string)$subkey['name']) . ' = ' . ''; - echo ''; + echo ''; } echo ''; } - break; + break; case 'CurvedRectangle': echo '', _((string)$key['name']), ' ', InputX($key['id'], $key->x), ' @@ -343,51 +314,45 @@ function SelectShowElement($keyName, $keyValue) { ', _('Radius'), ' = ', ' '; // Requires to standardize xml files from "radius" to "Radius" before changing the html name. + /* RCHACON: Attributes to add: + Show: To turn on/off the use of this rectangle. + Corners: Numbers of the corners to be rounded: 1, 2, 3, 4 or any combination (1=top left, 2=top right, 3=bottom right, 4=bottom left). + Style: (draw/fill): D (default), F, FD or DF. + Fill: Filling color.*/ -/* RCHACON: Attributes to add: -Show: To turn on/off the use of this rectangle. -Corners: Numbers of the corners to be rounded: 1, 2, 3, 4 or any combination (1=top left, 2=top right, 3=bottom right, 4=bottom left). -Style: (draw/fill): D (default), F, FD or DF. -Fill: Filling color.*/ - - break; + break; case 'Rectangle': // This case can be included in CurvedRectangle. echo '', _((string)$key['name']), ' ', InputX($key['id'], $key->x), ' ', InputY($key['id'], $key->y), ' ', InputWidth($key['id'], $key->width), ' ', InputHeight($key['id'], $key->height), ''; - break; + break; case 'Line': echo '' . _((string)$key['name']) . ''; - echo ''; - echo '', _('Start x co-ordinate').' = ' . ''; - echo '', _('Start y co-ordinate').' = ' . ''; - echo '', _('End x co-ordinate').' = ' . ''; - echo '', _('End y co-ordinate').' = ' . ''; - echo ''; - break; + echo ''; + echo '', _('Start x co-ordinate') . ' = ' . ''; + echo '', _('Start y co-ordinate') . ' = ' . ''; + echo '', _('End x co-ordinate') . ' = ' . ''; + echo '', _('End y co-ordinate') . ' = ' . ''; + echo ''; + break; default: - break; + break; } // END switch ($key['type']). echo '
'; } // END foreach ($FormDesign as $key). - -echo ' +echo '
- ', - '', // "Return" button. - '
'; + ', '', // "Return" button. +''; -echo '', - '
'; +echo '', ''; // END: Procedure division ---------------------------------------------------- -include('includes/footer.php'); +include ('includes/footer.php'); ?>