From: <dai...@us...> - 2012-04-25 09:11:59
|
Revision: 5280 http://web-erp.svn.sourceforge.net/web-erp/?rev=5280&view=rev Author: daintree Date: 2012-04-25 09:11:48 +0000 (Wed, 25 Apr 2012) Log Message: ----------- rewrite of label printing code Modified Paths: -------------- trunk/Labels.php trunk/PDFPrintLabel.php trunk/doc/Change.log trunk/includes/class.pdf.php trunk/includes/tcpdf/tcpdf.php trunk/sql/mysql/upgrade4.07-4.08.sql Modified: trunk/Labels.php =================================================================== --- trunk/Labels.php 2012-04-25 06:12:02 UTC (rev 5279) +++ trunk/Labels.php 2012-04-25 09:11:48 UTC (rev 5280) @@ -1,563 +1,450 @@ -<?php -/** - * <b>Labels XML file Managment</b> - * This program maintains the XML file containing the label defintions - * used to print the products prices tickets - * @author Marcos R Garcia <addsmgt at gmail dot com> - * @version 1.1 - * Last changes: 2010-08-31 - * - * - * Phil's notes: - * This is an example of clever code that works but IMHO is very hard to decipher and modify - sorry Marcos! - * It is in webERP because it fulfills a useful function on its own but don't expect to be able to modify it!! - * I would prefer this code was re-written in a manner consistent with the rest of webERP - * There are many meaningless variable names - * unecessary abrastaction at every turn - * No class is necessary for this script IMHO - * Data held in an xml file instead of the database - * Variable naming uses a lower case first character - * $debug is used - but is a webERP global to trap SQL errors for sysadmins - * -**/ - -$Version_adds= 1.1; - -include('includes/session.inc'); -$title=_('Label Templates Maintainance'); -include('includes/header.inc'); - -$debug=false; -include('includes/DefineLabelClass.php'); - - -//Phil why xml? Why not use the database like every other part of webERP for storing data - -$allLabels = //!< The variable $allLabels is the global variable that contains the list - getXMLFile($_SESSION['reports_dir'] . '/labels.xml'); //!< of all the label objects defined until now. In case of a fresh - //!< installation or an empty XML labels file it holds a NULL value. - -if ($debug) { - echo '<br />' ; - echo '<pre>'; - print_r($_POST); - echo '</pre>'; -//exit(); -} - -/** Check if some action has been requested -*/ -$showList=true; // By default will show the tamplates list - -/** - * Save the changes in template? - */ -if (isset($_POST['Update'])) { - // Get the data from the user input & validate it (not new) - //getData function - $Label=getData($_POST, false, $ok); - // If all OK try to update the requested label - if (!$ok OR !updateLabel($Label)) { - // show the data label from the input data as update data (id read only)} - showLabel($Label, _('Correct data'), $theme, false); - $showList=false; - } - -/** - * Save the data for a new template? - */ -} elseif (isset($_POST['Save'])) { - // Get the data from the user input & validate it for new id - $Label=getData($_POST, true, $ok); - if (!$ok OR !createLabel($Label)) { // - showLabel($Label, _('Correct data'), $theme, false); - $showList=false; - } - -/** - * Get the data from an old one to create a new template? - */ -} elseif (isset($_POST['Copy'])) { - $Label=$allLabels->getLabel($_POST['labelID']); - $Label->id = _('New ID'); // Well, where did I get it? of course from the user, but .. - showLabel($Label, _('Edit data new label'), $theme, false); - $showList=false; - -/** - * Change some data from an old template? - */ -} elseif (isset($_POST['Edit'])) { - $Label=$allLabels->getLabel($_POST['labelID']); - showLabel($Label, _('Edit data label'), $theme, true); - $showList=false; - -/** - * Eliminate an unnecesary template? - */ -} elseif (isset($_POST['Delete'])) { - $allLabels=deleteLabel($allLabels, $_POST['labelID']); - -/** - * Create a new template? - */ -} elseif (isset($_POST['New'])) { - showLabel(null, _('New label'), $theme); - $showList=false; - -/** - * Do nothing? only show the list (if it exist)) - */ -} elseif (isset($_POST['Cancel'])) { - ; // showLabelList - -/** - * No action requested, show all or get the first one - */ -} else { - if ($allLabels==null OR count($allLabels->label)<1) { - showLabel(null, _('There is no labels, create a new one'), $theme); - $showList=false; - } -} - -/** - * The default is to show the list of labels templates yet defined, - * the exception occurs when previously has been selected a particular - * template, for edit, copy or to create a new one - */ -if ($showList) { - echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/maintenance.png" title="' . _('Search') . '" alt="" />' . ' ' . $title.'</p>'; - showLabelsList($allLabels->label); -} -include('includes/footer.inc'); -exit(); - -/*! \brief getData - Gets the input data from the user's submit - * - * This code constructs a new objet Label from the form's data - * provided by the user. It validates the data too. - * @param $data The array of strings gived by the user - * @param $new This flag indicates that the labels is new, so check no repeated id - * @param $ok The variable where the routine gives the validation result. - * @return The Label object constructed qith the data, included errors. - */ -function getData($data, $new, &$ok) { - $ok = validData($data, $new); - return newLabel($data); -} - -function validData($data, $new) { - global $allLabels, $DimensionTags, $DataTags; - -// Check the heading data - $errors=array(); - if ($new) { - if (empty($data['id'])) { - $errors[]=_('Id required'); - } elseif ($allLabels!=null AND $allLabels->findLabel($data['id'])!==false){ - $errors[]=_('This id exists in previous list'); - } - } - if (empty($data['description'])) - $errors=_('the description is required'); - -// Check the dimensions data - foreach ($DimensionTags as $iTag=>$tag) { - if ($tag['type']=='s') { - continue; // select type does not require validation - } - $dd = trim($data[$iTag]); - $desc=$tag['desc']; - switch ($tag['type']) { - case 'n': - if (!is_numeric($dd)) - $errors[]= _('The value of').' '.$desc.' '._('would be numeric'); - elseif ((float)$data[$iTag]<=0) - $errors[]= _('The value of').' '.$desc.' '._('requires a positive value').$dd; - break; - case 'i': - if (!is_numeric($dd) OR (int)$data[$iTag]<=0) - $errors[]= _('The value of').' '.$tag['desc'].' '._('would be a positive integer'); - break; - } - } - // Checking consistency between data - // Rh > He - $tag = $DimensionTags[$iTag='Rh']; - if ((float)$data['Rh'] < (float)$data['He'] ) { - $desc=$tag['desc']; - $errors[]= _('The value of').' '.$desc.' '._('requires to be greater than the height of the labels'); - } - // Sh >= rows*Rh+Tm - $tag = $DimensionTags[$iTag='Sh']; - if ((float)$data['Sh'] <= (float)$data['Tm'] + ( (int)$data['Rows']*((float)$data['Rh']) ) ) { - $desc=$tag['desc']; - $errors[]= _('The value of').' '.$desc.' '._('requires to be greater than the height of all the rows, including the top margin'); - } - // Cw > Wi - $tag = $DimensionTags[$iTag='Cw']; - if ((float)$data['Cw'] < (float)$data['Wi'] ) { - $desc=$tag['desc']; - $errors[]= _('The value of').' '.$desc.' '._('requires to be greater than the width of the labels'); - } - // Sw >= Cols*Cw+Lm - $tag = $DimensionTags[$iTag='Sw']; - if ((float)$data['Sw'] <= (float)$data['Lm'] + ( (int)$data['Cols']*((float)$data['Cw']) ) ) { - $desc=$tag['desc']; - $errors[]= _('The value of').' '.$desc.' '._('requires to be greater than the width of all the cols, including the left margin'); - } - - $rowCount=0; - $jRow=0; - foreach ($data['row'] as $iRow=>$row) { - $jRow++; - if (empty($row)) continue; // The empty row indicates no data - $rowCount++; // we have data - - if (!is_numeric($row) ) $row=0; - else $row = (float)$row; - if ($row<=0) - $errors[]= _('The vert. pos. value would be positive') ." ($jRow)"; - elseif ((float)$row>(float)$data['He']) - $errors[]= _('The value of the vert. pos. would be less than')." ". $data['He'] ."($jRow)"; - - // now the rest of the line data is validated - foreach ($DataTags as $iTag=>$tag) { - if ($tag['type']=='s' // select type does not require validation - OR $iTag == 'row') continue; // the row is just validated - $dd = trim($data[$iTag][$iRow]); - $desc=$tag['desc']; - if ($tag['type']=='n') { - if (!is_numeric($dd)) - $errors[]= _('The value of').' '.$desc.' '._('would be numeric')." ($jRow)"; - elseif (empty($dd) OR (float)$dd<=0) - $errors[]= _('The value of').' '.$desc.' '._('requires a positive value')." ($jRow)"; - } - switch ($iTag) { - case 'font': - if ((float)$dd+$row >= (float)$data['He']) { - $errors[]= _('The value of').' '.$desc.' '._('in this position exceeds the label height'). - " ($jRow)"; - } - break; - case 'pos': - $posD = (float)$dd; - break; - case 'max': - if ((float)$dd+$posD >= (float)$data['Wi']) { - $errors[]= _('The position and lenght of the string leads the text to get out of the label'). " ($jRow)"; - } - break; - } - } - } - // Display the errors detected - if (count($errors)>0) { - foreach($errors as $err) - prnMsg($err); - return false; - } - return true; // all data are valid! -} - -/*! \brief Shows the label requested - * - * It shows the data label from the input $data as update data (id read only) - * if the third parameter is true or a fresh data label (new label). It is - * possible that the combination $data valid and $ReadOnly false occurs when - * invalid data needs to be recaptured because an error in a new label capture. - */ -function showLabel($Label, $msg, $theme, $ReadOnly=false) { - global $rootpath; - if ($Label==null) - $Label = newLabel(); - if ($ReadOnly) { - $name = 'Update'; - $value = _('Update'); - } else { - $name = 'Save'; - $value = _('Save'); - } - - $vCancel = _('Cancel'); - - $TableGD = setTableGD($Label, $ReadOnly); - $TableLines = setTableLines($Label->data->line); - - echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/maintenance.png" title="' . _('Search') . '" alt="" />' . ' ' . $msg.'</p>'; - - echo '<br /> - <form action="'.htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8').'" method="post"> - <div> - <input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" /> - <div class="centre"> - <table border="2" cellspacing="4" class="selection"> - <tbody> - <tr> - <td align="center"><img src="'.$rootpath.'/css/paramsLabel.png" alt="" /></td> - <td>'.$TableGD.'</td> - </tr> - <tr> - <td align="center"><img src="'.$rootpath.'/css/labelsDim.png" alt="" /></td> - <td>'.$TableLines.'</td> - </tr> - </tbody> - </table> - <br /> - <input type="submit" name="'.$name.'" value="'.$value.'" /> - <input type="submit" name="Cancel" value="'.$vCancel.'" /> - </div> - </div> - </form>'; -} - -function setTableGD($Label, $ReadOnly) { - global $GlobalTags, $DimensionTags; - $html='<table class="selection">'; - $html .= setDataFields($GlobalTags, 0, $Label, $specialTag='id', $ReadOnly); - $html .= setDataFields($DimensionTags, 1, $Label->dimensions); - $html .= ' - </table>'; - return $html; -} - -function setDataFields($tags, $withTagId, $data, $specialTag=false, $ReadOnly=false) { - $iCol=0; - $html = ''; - foreach ($tags as $iTag=>$tag) { - $vDat = (is_object($data) AND isset($data->$iTag))?$data->$iTag:''; - if ($tag['type']=='s') { - $input ='<select name="'. $iTag . '">'; - foreach ($tag['values'] as $i=>$val) { - $xSel = ($vDat==$i)?' selected="selected"' : ''; - $input .= ' - <option value="'. $i .'"'. $xSel .'>'.$val.'</option>'; - } - $input .= ' - </select>'; - } else { - $ro=''; - if ($ReadOnly AND $specialTag==$iTag) - $ro='readonly="readonly"'; - $input = '<input type="text" name="'. $iTag .'" value="'. $vDat .'" size="'. $tag['sz'] .'" maxlength="'. $tag['maxsz'] .'" '. $ro .' />'; - } - if (!$iCol++) // when zero begins a line - $html .= ' - <tr>'; - else - $iCol=0; - $wTag= $withTagId ? (' ('.$iTag.')') :''; - $html .= ' - <td align="right">' . $tag['desc'] . $wTag . ':</td> - <td>' . $input . '</td>'; - if (!$iCol) - $html .= ' - </tr>'; - } - if ($iCol) // if the count ends in an odd count, add the end of line - $html .= ' - </tr>'; - - return $html; -} - -function setTableLines($lineArray) { - global $DataTags; - $html='<table class="selection">'; - $html .= setTableHeader($DataTags); - - $iCount=MAX_LINES_PER_LABEL; - foreach ($lineArray as $i=>$data) { - $iCount--; - $html .= setLineFields($DataTags, $data); - } - while ($iCount-->0) - $html .= setLineFields($DataTags, null); - $html .= ' - </table>'; - return $html; -} - -function setTableHeader($tags) { - $html= ' - <tr>'; - foreach ($tags as $tit) - $html .= ' - <th>' . $tit['desc'] . '</th>'; - return $html . ' - </tr>'; -} - -function setLineFields($tags, $data) { - $html = ' - <tr>'; - foreach ($tags as $iTag=>$tag) { - $vDat = ($data!=null AND isset($data->$iTag))?$data->$iTag:''; - if ($tag['type']=='s') { - $input ='<select name="'. $iTag . '[]">'; - foreach ($tag['values'] as $kI=>$kVal) { - $xSel = ($vDat==$kI) ? ' selected="selected"':''; - $input .= ' - <option value="'. $kI .'"'. $xSel .'>'.$kVal.'</option>'; - } - $input .= ' - </select>'; - } else { - $input = '<input type="text" name="'. $iTag .'[]" value="'. $vDat .'" size="'. $tag['sz'] .'" maxlength="'. $tag['maxsz'] .'" />'; - } - $html .= ' - <td align="center">' . $input . '</td>'; - } - $html .= ' - </tr>'; - return $html; -} - -/*! \brief Shows the current label list -* -* When the user begin or finishes an maintance action, the program -* shows the current list, in particular, the ID and the description of the label. -* -* @param $list The label object list to be displayed -* @return Nothing -*/ -function showLabelsList($list) { - $txt= array(_('Label id'),_('Description'), _('Label array'), - _('New'), _('Edit'), _('Copy'), _('Delete'), - _('Do you really want to erase the label') - ); - // The header of the list - echo '<script type="text/javascript"> - function submitForm(formID, action, value) { - document.getElementById(\'action\').name=action; - document.getElementById(\'labelID\').value=value; - document.getElementById(formID).submit(); - } - function areYouSure(form, action, value) { - var r=confirm("'.$txt[7].'"); - if (r) { - submitForm(form, action, value); - } - } - </script> - <form action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '" method="post" id="form1"> - <div> - <input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" /> - <input type="hidden" name="action" id="action" value="" /> - <input type="hidden" name="labelID" id="labelID" value="" /> - </div> - </form> - <div class="centre"> - <table class="selection"> - <thead> - <tr> - <th>'.$txt[0].'</th> - <th>'.$txt[1].'</th> - <th>'.$txt[2].'</th> - <th><input type="submit" name="new" onclick="submitForm(\'form1\',\'New\',\'\');" value="'.$txt[3].'" /> - </th> - </tr> - </thead> - <tbody>'; - foreach ($list as $Label) { - $dim = (string)$Label->dimensions->Rows. ' x '. (string)$Label->dimensions->Cols; - echo ' - <tr><td>'. $Label->id . '</td> - <td>'. $Label->description . '</td> - <td><div class="centre">'. $dim . '</div></td> - <td><input type="submit" onclick="submitForm('. "'form1','Edit','". $Label->id . "');" .'" value="' . $txt[4]. '" /> - <input type="submit" onclick="submitForm('. "'form1','Copy','". $Label->id . "');" .'" value="' . $txt[5]. '" /> - <input type="submit" onclick="areYouSure('. "'form1','Delete','". $Label->id . "');" .'" value="' . $txt[6]. '" /> - </td> - </tr>'; - } - echo ' - </tbody> - </table> - </div>'; -} - -/*! \brief Generates a new label -* -* After the user gives the label data, this routine tries to insert -* the new label in the current list. -* -* @param $Label The object label that will replace an old one -* @return True when the update was ok -*/ -function createLabel($Label) { - global $allLabels; - $new = emptyList(); - $done=false; - if ($allLabels!=null) { - foreach ($allLabels as $oldLabel) { - if (!$done AND (string)$oldLabel->id >= (string)$Label->id) { - $new->addLabel($Label); - $done=true; - } - $new->addLabel($oldLabel); // inser data in the list, replacing the old one - } - } - if (!$done) - $new->addLabel($Label); - $allLabels = $new; - rewrite($allLabels); // rewrite it to the XML file - return true; -} - -/*! \brief Update the label data -* -* After the user modifies the label data this routine tries to update -* the corresponding structure in the label list with the object given. -* If the label with the id of the new one is found, the object could -* be accepted in the list and written to the XML file. -* -* @param $Label The object label that will replace an old one -* @return True when the update was ok -*/ -function updateLabel($Label) { - global $allLabels; - $new = emptyList(); - foreach ($allLabels as $oldLabel) { - if ((string)$oldLabel->id == (string)$Label->id) - $new->addLabel($Label); - else - $new->addLabel($oldLabel); // inser data in the list, replacing the old one - } - $allLabels = $new; - rewrite($allLabels); // rewrite it to the XML file - return true; -} - -/*! \brief Label elimination from the list. - * - * This routine eliminates one label from the global list $allLabels. It - * just find the index that correspond to the id given as input data. - * Because this function is called from the selection of a button with - * correct data, it would be unsual that some error exist, but it is - * included the code for the validation of some this strange case. - * - * @param $LabelID is the identifier of the label to delete. - * @see $allLabels - * @return true in case of success - */ -function deleteLabel($list, $LabelID) { - $new = emptyList(); - foreach ($list as $Label) { - if ((string)$Label->id!=$LabelID) - $new->addLabel($Label); - } - rewrite($new); - return $new; -} - -function rewrite($list) { - // First rename the previous XML file - if (is_file(LABELS_FILE) AND !rename(LABELS_FILE, LABELS_FILE.".bak")) - abortMsg(_('Could not rename the previous file.')); - $result=$list->asXML(LABELS_FILE); - if (!$result) - abortMsg(_('Could not create the new XML file.').': '.LABELS_FILE); -} - +<?php + +/* $Id: Labels.php 4950 2012-02-22 06:26:38Z daintree $*/ + +include('includes/session.inc'); +$title = _('Label Templates'); +include('includes/header.inc'); + +//define PaperSize array sizes in pdf points +$PaperSize = array('A4', + 'A4_Landscape', + 'A5', + 'A5_Landscape', + 'A3', + 'A3_Landscape', + 'Letter', + 'Letter_Landscape', + 'Legal', + 'Legal_Landscape'); + + +echo '<p class="page_title_text"> + <img src="'.$rootpath.'/css/'.$theme.'/images/maintenance.png" title="' . _('Label Template Maintenance') + . '" alt="" />' . $title. ' + </p>'; + +if (isset($_POST['SelectedLabelID'])){ + $SelectedLabelID =$_POST['SelectedLabelID']; + if (ctype_digit($_POST['NoOfFieldsDefined'])){ //Now Process any field updates + + for ($i=0;$i<=$_POST['NoOfFieldsDefined'];$i++){ + + if (ctype_digit($_POST['VPos' . $i]) + AND ctype_digit($_POST['HPos' . $i]) + AND ctype_digit($_POST['FontSize' . $i])){ // if all entries are integers + + $result =DB_query("UPDATE labelfields SET fieldvalue='" . $_POST['FieldName' . $i] . "', + vpos='" . $_POST['VPos' . $i] . "', + hpos='" . $_POST['HPos' . $i] . "', + fontsize='" . $_POST['FontSize' . $i] . "', + barcode='" . $_POST['Barcode' . $i] . "' + WHERE labelfieldid='" . $_POST['LabelFieldID' . $i] . "'", + $db); + } else { + prnMsg (_('Entries for Vertical Position Horizonal Position and Font Size must be integers.'),'error'); + } + } + } + if (ctype_digit($_POST['VPos']) AND ctype_digit($_POST['HPos']) AND ctype_digit($_POST['FontSize'])){ + //insert the new label field entered + $result = DB_query("INSERT INTO labelfields (labelid, + fieldvalue, + vpos, + hpos, + fontsize, + barcode) + VALUES ('" . $SelectedLabelID . "', + '" . $_POST['FieldName'] . "', + '" . $_POST['VPos'] . "', + '" . $_POST['HPos'] . "', + '" . $_POST['FontSize'] . "', + '" . $_POST['Barcode'] . "')", + $db); + } +} elseif(isset($_GET['SelectedLabelID'])){ + $SelectedLabelID =$_GET['SelectedLabelID']; + if (isset($_GET['DeleteField'])){ //then process any deleted fields + $result = DB_query("DELETE FROM labelfields WHERE labelfieldid='" . $_GET['DeleteField'] . "'",$db); + } +} + +if (isset($_POST['submit'])) { + $InputError = 0; + /* actions to take once the user has clicked the submit button + ie the page has called itself with some user input */ + if ( trim( $_POST['Description'] ) == '' ) { + $InputError = 1; + prnMsg( _('The label description may not be empty'), 'error'); + } + $Message = ''; + if (isset($SelectedLabelID)) { + + /*SelectedLabelID could also exist if submit had not been clicked this code + would not run in this case cos submit is false of course see the + delete code below*/ + + $sql = "UPDATE labels SET papersize ='" . $_POST['PaperSize'] . "', + description = '" . $_POST['Description'] . "', + height = '" . $_POST['Height'] . "', + topmargin = '". $_POST['TopMargin'] . "', + width = '". $_POST['Width'] . "', + leftmargin = '". $_POST['LeftMargin'] . "', + rowheight = '". $_POST['RowHeight'] . "', + columnwidth = '". $_POST['ColumnWidth'] . "' + WHERE labelid = '" . $SelectedLabelID . "'"; + + $ErrMsg = _('The update of this label template failed because'); + $result = DB_query($sql,$db,$ErrMsg); + + $Message = _('The label template has been updated'); + + } elseif ($InputError !=1) { + + /*Selected label is null cos no item selected on first time round so must be adding a record must be submitting new entries in the new label form */ + + $sql = "INSERT INTO labels (papersize, + description, + height, + topmargin, + width, + leftmargin, + rowheight, + columnwidth) + VALUES ('" . $_POST['PaperSize'] . "', + '" . $_POST['Description'] . "', + '" . $_POST['Height'] . "', + '" . $_POST['TopMargin'] . "', + '" . $_POST['Width'] . "', + '" . $_POST['LeftMargin'] . "', + '" . $_POST['RowHeight'] . "', + '" . $_POST['ColumnWidth'] . "')"; + + $ErrMsg = _('The addition of this label failed because'); + $result = DB_query($sql,$db,$ErrMsg); + $Message = _('The new label template has been added to the database'); + } + //run the SQL from either of the above possibilites + if (isset($InputError) AND $InputError !=1) { + unset( $_POST['PaperSize']); + unset( $_POST['Description']); + unset( $_POST['Width']); + unset( $_POST['Height']); + unset( $_POST['TopMargin']); + unset( $_POST['LeftMargin']); + unset( $_POST['ColumnWidth']); + unset( $_POST['RowHeight']); + + } + + prnMsg($Message); + +} elseif (isset($_GET['delete'])) { +//the link to delete a selected record was clicked instead of the submit button + + /*Cascade deletes in TaxAuthLevels */ + $result = DB_query("DELETE FROM labelfields WHERE labelid= '" . $SelectedLabelID . "'",$db); + $result = DB_query("DELETE FROM labels WHERE labelid= '" . $SelectedLabelID . "'",$db); + prnMsg(_('The selected label template has been deleted'),'success'); + unset ($SelectedLabelID); +} + +if (!isset($SelectedLabelID)) { + +/* It could still be the second time the page has been run and a record has been selected for modification - SelectedLabelID will exist because it was sent with the new call. If its the first time the page has been displayed with no parameters then none of the above are true and the list of label templates will be displayed with links to delete or edit each. These will call the same page again and allow update/input or deletion of the records*/ + + $sql = "SELECT labelid, + description, + papersize, + height, + width, + topmargin, + leftmargin, + rowheight, + columnwidth + FROM labels"; + + $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The defined label templates could not be retrieved because'); + $DbgMsg = _('The following SQL to retrieve the label templates was used'); + $result = DB_query($sql,$db,$ErrMsg,$DbgMsg); + + if (DB_num_rows($result)>0){ + echo '<table class="selection"> + <tr> + <th>' . _('Description') . '</th> + <th>' . _('Page Size') . '</th> + <th>' . _('Height') . '</th> + <th>' . _('Width') . '</th> + <th>' . _('Row Height') . '</th> + <th>' . _('Column Width') . '</th> + </tr>'; + $k=0; + while ($myrow = DB_fetch_array($result)) { + + if ($k==1){ + echo '<tr class="EvenTableRows">'; + $k=0; + } else { + echo '<tr class="OddTableRows">'; + $k++; + } + + printf('<td>%s</td> + <td>%s</td> + <td>%s</td> + <td>%s</td> + <td>%s</td> + <td>%s</td> + <td><a href="%sSelectedLabelID=%s">' . _('Edit') . '</a></td> + <td><a href="%sSelectedLabelID=%s&delete=yes" onclick="return confirm(\'' . _('Are you sure you wish to delete this label?') . '\');">' . _('Delete') . '</a></td> + </tr>', + $myrow['description'], + $myrow['papersize'], + $myrow['height'], + $myrow['width'], + $myrow['rowheight'], + $myrow['columnwidth'], + htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '?', + $myrow['labelid'], + htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '?', + $myrow['labelid'], + $rootpath . '/LabelFields.php?', + $myrow['labelid']); + + } + //END WHILE LIST LOOP + + //end of ifs and buts! + + echo '</table><p>'; + } //end if there are label definitions to show +} + +if (isset($SelectedLabelID)) { + echo '<div class="centre"> + <a href="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') .'">' . _('Review all defined label records') . '</a> + </div>'; +} + +echo '<p><form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">'; +echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />'; + +if (isset($SelectedLabelID)) { + //editing an existing label + + $sql = "SELECT papersize, + description, + height, + width, + topmargin, + leftmargin, + rowheight, + columnwidth + FROM labels + WHERE labelid='" . $SelectedLabelID . "'"; + + $result = DB_query($sql, $db); + $myrow = DB_fetch_array($result); + + $_POST['PaperSize'] = $myrow['papersize']; + $_POST['Description'] = $myrow['description']; + $_POST['Height'] = $myrow['height']; + $_POST['TopMargin'] = $myrow['topmargin']; + $_POST['Width'] = $myrow['width']; + $_POST['LeftMargin'] = $myrow['leftmargin']; + $_POST['RowHeight'] = $myrow['rowheight']; + $_POST['ColumnWidth'] = $myrow['columnwidth']; + + echo '<input type="hidden" name="SelectedLabelID" value="' . $SelectedLabelID . '" />'; + +} //end of if $SelectedLabelID only do the else when a new record is being entered + + +if (!isset($_POST['Description'])) { + $_POST['Description']=''; +} +echo '<table class="selection"> + <tr> + <td><img src="css/paramsLabel.png"></td> + <td><table> + <tr> + <td>' . _('Label Description') . ':</td> + <td><input type="text" name="Description" size="21" maxlength="20" value="' . $_POST['Description'] . '" /></td> + </tr> + <tr> + <td>' . _('Label Paper Size') . ':</td> + <td><select name="PaperSize">'; + +foreach($PaperSize as $PaperType) { + if (isset($_POST['PaperSize']) AND $PaperType==$_POST['PaperSize']) { + echo '<option selected="selected" value="'; + } else { + echo '<option value="'; + } + echo $PaperType . '">' . $PaperType . '</option>'; + +} //end while loop + +echo '</select></td> + </tr>'; + +if (!isset($_POST['Height'])) { + $_POST['Height']=0; +} +if (!isset($_POST['TopMargin'])) { + $_POST['TopMargin']=5; +} +if (!isset($_POST['Width'])) { + $_POST['Width']=0; +} +if (!isset($_POST['LeftMargin'])) { + $_POST['LeftMargin']=10; +} +if (!isset($_POST['RowHeight'])) { + $_POST['RowHeight']=0; +} + +if (!isset($_POST['ColumnWidth'])) { + $_POST['ColumnWidth']=0; +} +echo '<tr> + <td>' . _('Label Height') . ' - (He):</td> + <td><input type="text" name="Height" size="4" maxlength="4" value="' . $_POST['Height'] . '" /></td> + </tr> + <tr> + <td>' . _('Label Width') . ' - (Wi):</td> + <td><input type="text" name="Width" size="4" maxlength="4" value="' . $_POST['Width'] . '" /></td> + </tr> + <tr> + <td>' . _('Top Margin') . ' - (Tm):</td> + <td><input type="text" name="TopMargin" size="4" maxlength="4" value="' . $_POST['TopMargin'] . '" /></td> + </tr> + <tr> + <td>' . _('Left Margin') . ' - (Lm):</td> + <td><input type="text" name="LeftMargin" size="4" maxlength="4" value="' . $_POST['LeftMargin'] . '" /></td> + </tr> + <tr> + <td>' . _('Row Height') . ' - (Rh):</td> + <td><input type="text" name="RowHeight" size="4" maxlength="4" value="' . $_POST['RowHeight'] . '" /></td> + </tr> + <tr> + <td>' . _('Column Width') . ' - (Cw):</td> + <td><input type="text" name="ColumnWidth" size="4" maxlength="4" value="' . $_POST['ColumnWidth'] . '" /></td> + </tr> + </table></td></tr> + </td></tr> + </table>'; + +if (isset($SelectedLabelID)) { + //get the fields to show + $SQL = "SELECT labelfieldid, + labelid, + fieldvalue, + vpos, + hpos, + fontsize, + barcode + FROM labelfields + WHERE labelid = '" . $SelectedLabelID . "' + ORDER BY vpos DESC"; + $ErrMsg = _('Could note get the label fields because'); + $result = DB_query($SQL,$db,$ErrMsg); + $i=0; + echo '<table class="selection"> + <tr> + <td><img src="css/labelsDim.png"></td> + <td><table> + <tr> + <th>' . _('Field') . '</th> + <th>' . _('Vertical') . '<br />' . _('Position') . '<br />(VPos)</th> + <th>' . _('Horizonal') . '<br />' . _('Position') . '<br />(HPos)</th> + <th>' . _('Font Size') . '</th> + <th>' . _('Bar-code') . '</th> + </tr>'; + if (DB_num_rows($result)>0){ + $k=0; + while ($myrow = DB_fetch_array($result)) { + + if ($k==1){ + echo '<tr class="EvenTableRows">'; + $k=0; + } else { + echo '<tr class="OddTableRows">'; + $k++; + } + + echo '<input type="hidden" name="LabelFieldID' . $i . '" value="' . $myrow['labelfieldid'] . '" /> + <td><select name="FieldName' . $i . '">'; + if ($myrow['fieldvalue']=='itemcode'){ + echo '<option selected="selected" value="itemcode">' . _('Item Code') . '</option>'; + } else { + echo '<option value="itemcode">' . _('Item Code') . '</option>'; + } + if ($myrow['fieldvalue']=='itemdescription'){ + echo '<option selected="selected" value="itemdescription">' . _('Item Description') . '</option>'; + } else { + echo '<option value="itemdescription">' . _('Item Descrption') . '</option>'; + } + if ($myrow['fieldvalue']=='barcode'){ + echo '<option selected="selected" value="barcode">' . _('Item Barcode') . '</option>'; + } else { + echo '<option value="barcode">' . _('Item Barcode') . '</option>'; + } + if ($myrow['fieldvalue']=='price'){ + echo '<option selected="selected" value="price">' . _('Price') . '</option>'; + } else { + echo '<option value="price">' . _('Price') . '</option>'; + } + echo '</select></td> + <td><input type="text" name="VPos' . $i . '" size="4" maxlength="4" value="' . $myrow['vpos'] . '" /></td> + <td><input type="text" name="HPos' . $i . '" size="4" maxlength="4" value="' . $myrow['hpos'] . '" /></td> + <td><input type="text" name="FontSize' . $i . '" size="4" maxlength="4" value="' . $myrow['fontsize'] . '" /></td> + <td><select name="Barcode' . $i . '">'; + if ($myrow['barcode']==0){ + echo '<option selected="selected" value="0">' . _('No') . '</option> + <option value="1">' . _('Yes') . '</option>'; + } else { + echo '<option selected="selected" value="1">' . _('Yes') . '</option> + <option value="0">' . _('No') . '</option>'; + } + echo '</select></td> + <td><a href="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '?SelectedLabelID=' . $SelectedLabelID . '&DeleteField=' . $myrow['labelfieldid'] .' onclick="return confirm(\'' . _('Are you sure you wish to delete this label field?') . '\');">' . _('Delete') . '</a></td> + </tr>'; + $i++; + } + //END WHILE LIST LOOP + $i--; //last increment needs to be wound back + echo '<input type="hidden" name="NoOfFieldsDefined" value="' . $i . '" />'; + } //end if there are label definitions to show + + echo '<tr> + <td><select name="FieldName"> + <option value="itemcode">' . _('Item Code') . '</option> + <option value="itemdescription">' . _('Item Descrption') . '</option> + <option value="barcode">' . _('Item Barcode') . '</option> + <option value="price">' . _('Price') . '</option> + </select></td> + <td><input type="text" size="4" maxlength="4" name="VPos" /></td> + <td><input type="text" size="4" maxlength="4" name="HPos" /></td> + <td><input type="text" size="4" maxlength="4" name="FontSize" /></td> + <td><select name="Barcode"> + <option value="1">' . _('Yes') . '</option> + <option selected="selected" value="0">' . _('No') . '</option> + </select></td> + </tr> + </table> + </td> + </tr> + </table> + <p />'; +} + +echo '<br /> + <div class="centre"> + <input type="submit" name="submit" value="' . _('Enter Information') . '" /> + </div> + </form>'; + +include('includes/footer.inc'); + ?> \ No newline at end of file Modified: trunk/PDFPrintLabel.php =================================================================== --- trunk/PDFPrintLabel.php 2012-04-25 06:12:02 UTC (rev 5279) +++ trunk/PDFPrintLabel.php 2012-04-25 09:11:48 UTC (rev 5280) @@ -1,522 +1,260 @@ <?php +/* $Id: PDFPriceLabels.php 5228 2012-04-06 02:48:00Z vvs2012 $*/ -/* $Id: PDFPrintLabel.php 4285 2010-12-22 16:01:51Z tim_schofield $*/ - -$Version_adds= '1.2'; - include('includes/session.inc'); -require_once('includes/DefineLabelClass.php'); -$MsgErr=null; -$DecimalPlaces=2; -$pdf= null; -/* The variable $AllLabels is the global variable that contains the list */ -$AllLabels = getXMLFile(LABELS_FILE); -/* of all the label objects defined until now. In case of a fresh -installation or an empty XML labels file it holds a NULL value. +$PtsPerMM = 2.83465; //pdf millimetres to points -If there is no label templates, the user could select to set up a new one -*/ -if ($AllLabels==null) { +if (isset($_POST['PrintPDF']) + AND isset($_POST['FromCriteria']) + AND mb_strlen($_POST['FromCriteria'])>=1 + AND isset($_POST['ToCriteria']) + AND mb_strlen($_POST['ToCriteria'])>=1){ + + $result = DB_query("SELECT papersize, + description, + width*" . $PtsPerMM . " as label_width, + height*" . $PtsPerMM . " as label_height, + rowheight*" . $PtsPerMM . " as label_rowheight, + columnwidth*" . $PtsPerMM . " as label_columnwidth, + topmargin*" . $PtsPerMM . " as label_topmargin, + leftmargin*" . $PtsPerMM . " as label_leftmargin + FROM labels + WHERE labelid='" . $_POST['LabelID'] . "'", + $db); + $LabelDimensions = DB_fetch_array($result); + $PaperSize = $LabelDimensions['papersize']; + include('includes/PDFStarter.php'); + $Top_Margin = $LabelDimensions['label_topmargin']; + $Left_Margin = $LabelDimensions['label_leftmargin']; - abortMsg( _('There isn\'t any label template to select for printing. Click') . - ' <a href="Labels.php"><b>' . _('HERE'). '</b></a> '. _('to set up a new one') ); -} + $pdf->addInfo('Title', $LabelDimensions['description'] . ' ' . _('Price Labels') ); + $pdf->addInfo('Subject', $LabelDimensions['description'] . ' ' . _('Price Labels') ); -/** - * The option print was selected, first it is checked if there are enough data - * to print the labels. - */ -if (isset($_POST['PrintPDF']) OR isset($_POST['PDFTest']) ) { - if (!isset($_POST['QtyByItem']) OR (int)$_POST['QtyByItem']<1) - $MsgErr = _('You must specify the number of labels per item required'); - else { - if (count($_POST['StockID'])<1) - $MsgErr = _('You must select the items to be printed'); - else { - // - $label = $AllLabels->getLabel($_POST['LabelID']); - list($dimensions, $lines) = resizeLabel($label); - $formatPage = getPageDimensions($dimensions); - list($Page_Width, - $Page_Height, - $Top_Margin, - $Bottom_Margin, - $Left_Margin, - $Right_Margin) = $formatPage; - - // Do it! - $PaperSize = 'User_special'; // Don't use any of the predefined sizes - $DocumentPaper='LETTER'; - $DocumentOrientation='P'; // Correccion para la version trunk :( - include('includes/PDFStarter.php'); - if ($Version>='3.12') - $pdf->setPageFormat($formatPage); - $ok = printLabels( - $dimensions, - $lines, - intval($_POST['QtyByItem']), - $_POST['Currency'], - $_POST['SalesType'], - $_POST['StockID'], - FormatDateForSQL($_POST['EffectiveDate']) - ); - - if ($ok) - exit(); // the print was success - else // Has been ocurred an error - $MsgErr = _('There was an error. Consult your IT staff'); + $result = DB_query("SELECT fieldvalue, + vpos, + hpos, + fontsize, + barcode + FROM labelfields + WHERE labelid = '" . $_POST['LabelID'] . "'", + $db); + $LabelFields = array(); + $i=0; + while ($LabelFieldRow = DB_fetch_array($result)){ + if ($LabelFieldRow['fieldvalue'] == 'itemcode'){ + $LabelFields[$i]['FieldValue'] = 'stockid'; + } elseif ($LabelFieldRow['fieldvalue'] == 'itemdescription'){ + $LabelFields[$i]['FieldValue'] = 'description'; + } else { + $LabelFields[$i]['FieldValue'] = $LabelFieldRow['fieldvalue']; } + $LabelFields[$i]['VPos'] = $LabelFieldRow['vpos']*$PtsPerMM; + $LabelFields[$i]['HPos'] = $LabelFieldRow['hpos']*$PtsPerMM; + $LabelFields[$i]['FontSize'] = $LabelFieldRow['fontsize']; + $LabelFields[$i]['Barcode'] = $LabelFieldRow['barcode']; + $i++; } -} + + $SQL = "SELECT prices.stockid, + stockmaster.description, + stockmaster.barcode, + prices.price, + currencies.decimalplaces + FROM stockmaster INNER JOIN stockcategory + ON stockmaster.categoryid=stockcategory.categoryid + INNER JOIN prices + ON stockmaster.stockid=prices.stockid + INNER JOIN currencies + ON prices.currabrev=currencies.currabrev + WHERE stockmaster.categoryid >= '" . $_POST['FromCriteria'] . "' + AND stockmaster.categoryid <= '" . $_POST['ToCriteria'] . "' + AND prices.typeabbrev='" . $_POST['SalesType'] . "' + AND prices.currabrev='" . $_POST['Currency'] . "' + AND prices.startdate<='" . FormatDateForSQL($_POST['EffectiveDate']) . "' + AND (prices.enddate='0000-00-00' OR prices.enddate>'" . FormatDateForSQL($_POST['EffectiveDate']) . "') + AND prices.debtorno='' + ORDER BY prices.currabrev, + stockmaster.categoryid, + stockmaster.stockid, + prices.startdate"; + + $LabelsResult = DB_query($SQL,$db,'','',false,false); -/** - * There is not activated option print, then show the window for capture the printing - * options. - */ - -$title = _('Print Price Labels'); -include('includes/header.inc'); - -if ($MsgErr!=null) { - prnMsg($MsgErr,'warn'); -} - -showLabelOptions(); - -include('includes/footer.inc'); -exit(); - -function showLabelOptions() { - global $AllLabels, $DecimalPlaces, $rootpath, $theme; - $txt = array( - _('Label Sticker Printing'), - _('Select label type'), - _('Number of labels per item'), - _('Price list'), - _('Currency'), - _('Category'), - _('Effective Date'), - _('Update values') - ); - if (!isset($_POST['LabelID'])) - $_POST['LabelID']=(string)$AllLabels->label[0]->id; - $OptionLabels = selLabels($_POST['LabelID']); - if (!isset($_POST['QtyByItem'])) - $_POST['QtyByItem']=1; - if (!isset($_POST['SalesType'])) - $_POST['SalesType']=$_SESSION['DefaultPriceList']; - $OptionSales = selSalesType($_POST['SalesType']); - - if (!isset($_POST['Currency'])){ - $_POST['Currency']=$_SESSION['CompanyRecord']['currencydefault']; + if (DB_error_no($db) !=0) { + $title = _('Price Label') . ' - ' . _('Problem Report....'); + include('includes/header.inc'); + prnMsg( _('The Price Labels could not be retrieved by the SQL because'). ' - ' . DB_error_msg($db), 'error'); + echo '<br /><a href="' .$rootpath .'/index.php">'. _('Back to the menu'). '</a>'; + if ($debug==1){ + prnMsg(_('For debugging purposes the SQL used was:') . $SQL,'error'); + } + include('includes/footer.inc'); + exit; } - $DecimalPlaces=getDecimalPlaces($_POST['Currency']); + if (DB_num_rows($LabelsResult)==0){ + $title = _('Print Price Labels Error'); + include('includes/header.inc'); + prnMsg(_('There were no price labels to print out for the category specified'),'warn'); + echo '<br /><a href="'.htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">'. _('Back').'</a>'; + include('includes/footer.inc'); + exit; + } - $OptionCurrency = selCurrency($_POST['Currency']); - if (!isset($_POST['Category'])) - $_POST['Category']=''; - $OptionsCategory = selCategory($_POST['Category']); + $style = array( + 'position' => '', + 'align' => 'C', + 'stretch' => false, + 'fitwidth' => true, + 'cellfitalign' => '', + 'border' => false, + 'hpadding' => 'auto', + 'vpadding' => 'auto', + 'fgcolor' => array(0,0,0), + 'bgcolor' => false, //array(255,255,255), + 'text' => false, + 'font' => 'helvetica', + 'fontsize' => 8, + 'stretchtext' => 4 ); - $TableItems = tableItems($_POST['Category'], $okItems); + $PageNumber=1; + //go down first then accross + $YPos = $Page_Height - $Top_Margin; //top of current label + $XPos = $Left_Margin; // left of current label - if (!isset($_POST['EffectiveDate'])){ - $_POST['EffectiveDate']=Date($_SESSION['DefaultDateFormat']); + while ($PriceLabels = DB_fetch_array($LabelsResult,$db)){ + foreach ($LabelFields as $Field){ + if ($Field['FieldValue'] == 'price'){ //need to format for the number of decimal places + $LeftOvers = $pdf->addTextWrap($XPos+$Field['HPos'],$YPos-$LabelDimensions['label_height']+$Field['VPos'],$LabelDimensions['label_width']-$Field['HPos'],$Field['FontSize'],locale_number_format($PriceLabels['price'],$PriceLabels['decimalplaces']),'right'); + } elseif($Field['Barcode']==1) { + + /* write1DBarcode($code, $type, $x='', $y='', $w='', $h='', $xres='', $style='', $align='') + * Note that the YPos for this function is based on the opposite origin for the Y axis i.e from the bottom not from the top! + */ + + $pdf->write1DBarcode(str_replace('_','',$PriceLabels[$Field['FieldValue']]), 'C128',$XPos+$Field['HPos'],$Page_Height - $YPos+$LabelDimensions['label_height']-$Field['VPos']-$Field['FontSize'],$LabelDimensions['label_width']-$Field['HPos'], $Field['FontSize'], 0.4, $style, 'N'); + } else { + $LeftOvers = $pdf->addTextWrap($XPos+$Field['HPos'],$YPos-$LabelDimensions['label_height']+$Field['VPos'],$LabelDimensions['label_width']-$Field['HPos'],$Field['FontSize'],$PriceLabels[$Field['FieldValue']]); + } + } // end loop through label fields + //setup $YPos and $XPos for the next label + if (($YPos - $LabelDimensions['label_rowheight']) < $LabelDimensions['label_height']){ + /* not enough space below the above label to print a new label + * so the above was the last label in the column + * need to start either a new column or new page + */ + if (($Page_Width - $XPos - $LabelDimensions['label_columnwidth']) < $LabelDimensions['label_width']) { + /* Not enough space to start a new column so we are into a new page + */ + $pdf->newPage(); + $PageNumber++; + $YPos = $Page_Height - $Top_Margin; //top of next label + $XPos = $Left_Margin; // left of next label + } else { + /* There is enough space for another column */ + $YPos = $Page_Height - $Top_Margin; //back to the top of next label column + $XPos += $LabelDimensions['label_columnwidth']; // left of next label + } + } else { + /* There is space below to print a label + */ + $YPos -= $LabelDimensions['label_rowheight']; //Top of next label + } } - $SendButton = '<br /><div class="centre"><input type="submit" name="PrintPDF" value="'. _('Print labels') .'" /> - <input type="submit" name="PDFTest" value="'. _('Print labels with borders') .'" /></div>'; - $iTxt=0; - echo '<script type="text/javascript"> - function setAll(all) { - var x=document.getElementById("form1"); - for (var i=0;i<x.length;i++) { - if (x.elements[i].id=="item"); - x.elements[i].checked=all.checked; - } - } - </script>'; - echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/maintenance.png" title="' . _('Search') . '" alt="" />' . ' ' .$txt[$iTxt++].'</p>'; - echo '<form action="'.htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8').'" method="post" id="form1">'; - echo '<div>'; - echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />'; - echo '<table class="selection">'; - echo '<tbody>'; - echo '<tr> - <td class="number">'.$txt[$iTxt++].':</td> - <td><select name="LabelID">'. - $OptionLabels - .'</select></td> - </tr>'; - echo '<tr> - <td class="number">'.$txt[$iTxt++].':</td> - <td><input type="text" class="number" name="QtyByItem" value="'.$_POST['QtyByItem'].'" size="2" - maxlength="4" /></td> - </tr>'; - echo '<tr> - <td class="number">'.$txt[$iTxt++].':</td> - <td><select name="SalesType" onchange="ReloadForm(form1.refresh)"> - '.$OptionSales.' - </select></td> - </tr>'; - echo '<tr> - <td class="number">'.$txt[$iTxt++].':</td> - <td><select name="Currency" onchange="ReloadForm(form1.refresh)"> - '.$OptionCurrency.' - </select></td> - </tr>'; - echo '<tr> - <td class="number">'.$txt[$iTxt++].':</td> - <td><select name="Category" onchange="ReloadForm(form1.refresh)"> - '.$OptionsCategory.' - </select> </td> - </tr>'; - echo '<tr><td class="number">'.$txt[$iTxt++].':</td> - <td><input type="text" class="date" alt="'.$_SESSION['DefaultDateFormat'].'" name="EffectiveDate" size="11" maxlength="10" value="' . $_POST['EffectiveDate'] . '" /></td></tr>'; - echo '<tr> - <th colspan="2"> - <input type="submit" name="refresh" value="' . _('Refresh options') . '" /> - </th> - </tr>'; - echo '<tr> - <td colspan="2"> - '.$TableItems.' - </td> - </tr>'; - echo '</tbody> - </table> - '.$SendButton.' - </div> - </form>'; -} + $FileName=$_SESSION['DatabaseName']. '_' . _('Price_Labels') . '_' . date('Y-m-d').'.pdf'; + ob_clean(); + $pdf->OutputD($FileName); + $pdf->__destruct(); -function selLabels($type) { - global $AllLabels; - $list=array(); +} else { /*The option to print PDF was not hit */ - foreach ($AllLabels->label as $label) - $list[(string)$label->id] = (string)$label->description; + $title= _('Price Labels'); + include('includes/header.inc'); - return selectOptions($list, $type); -} + echo '<p class="page_title_text"><img src="' . $rootpath . '/css/' . $theme . '/images/customer.png" title="' . _('Price Labels') . '" alt="" /> + ' . ' ' . _('Print Price Labels') . '</p>'; -function selSalesType($type) { - return selectTable('SELECT typeabbrev, sales_type FROM salestypes ORDER BY sales_type', $type); -} + if (!isset($_POST['FromCriteria']) OR !isset($_POST['ToCriteria'])) { -function selCurrency($curr) { - return selectTable('SELECT currabrev, currency FROM currencies', $curr); -} + /*if $FromCriteria is not set then show a form to allow input */ -function selCategory(&$categ) { - return selectTable('SELECT categoryid, categorydescription FROM stockcategory ORDER BY categorydescription', $categ); -} - -function selectTable($sql, &$currentKey) { - global $db; - $result = DB_query($sql, $db); - while ($myrow=DB_fetch_row($result)) { - if (empty($currentKey)) - $currentKey=$myrow[0]; - $list[$myrow[0]] = $myrow[1]; - } - DB_free_result($result); - return selectOptions($list, $currentKey); -} - -function selectOptions($list, $currentKey) { - $html=''; - foreach ($list as $key=>$value) { - $xs = ($currentKey==$key) ? ' selected="selected"':''; - $html .= ' - <option value="'. $key .'"'. $xs .'>'. $value. '</option>'; - } - return $html; -} - -function tableItems($CategoryID, &$ok) { - global $db, $DecimalPlaces; - - if (empty($CategoryID)) { - $ok=false; - return noneButton( _('Select a Category') ); - } - $result = getStockItems($CategoryID, $_POST['Currency'], $_POST['SalesType'], FormatDateForSQL($_POST['EffectiveDate'])); - if (!DB_num_rows($result)) { - $ok=false; - return noneButton( _('This category has no items to show') ); - } - - $txt=array(_('Code'), - _('Description'), - _('Price'). '<br />('.$_POST['Currency'].')', - _('All') - ); - $ix=0; - // The table's header - $html= '<table border="0" width="100%"> - <thead> - <tr> - <th>'.$txt[$ix++].'</th> - <th>'.$txt[$ix++].'</th> - <th>'.$txt[$ix++].'</th> - <th colspan="2" align="center">'.$txt[$ix++].' - <input type="checkbox" checked="checked" onclick="setAll(this);" /> - </th> + echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '" method="post">'; + echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />'; + echo '<table class="selection">'; + echo '<tr> + <td>' . _('Label to print') . ':</td> + <td><select name="LabelID">'; + + $LabelResult = DB_query("SELECT labelid, description FROM labels",$db); + while ($LabelRow = DB_fetch_array($LabelResult)){ + echo '<option value="' . $LabelRow['labelid'] . '">' . $LabelRow['description'] . '</option>'; + } + echo '</select></td> </tr> - </thead> + <tr> + <td>'. _('From Inventory Category Code') .':</td> + <td><select name="FromCriteria">'; - <tbody>'; - $ok=true; - $odd=true; - while ($myrow=DB_fetch_array($result)) { - $price = locale_number_format($myrow['price'],$DecimalPlaces); - $oddEven=$odd?"Odd":"Even"; - $odd = !$odd; - $html .= <<<ZZZ - <tr class="{$oddEven}TableRows"> - <td>{$myrow['stockid']}</td> - <td>{$myrow['description']}</td> - <td class="number">{$price}</td> - <td><div class="centre"> - <input type="checkbox" checked="checked" name="StockID[{$myrow['stockid']}]" id="item" /> - </div> - </td> - <td> </td> - </tr> -ZZZ; - } - return $html . ' - </tbody> - </table>'; -} + $CatResult= DB_query("SELECT categoryid, categorydescription FROM stockcategory ORDER BY categoryid",$db); + while ($myrow = DB_fetch_array($CatResult)){ + echo '<option value="' . $myrow['categoryid'] . '">' . $myrow['categoryid'] . ' - ' . $myrow['categorydescription'] . '</option>'; + } + echo '</select></td></tr>'; -function noneButton($msg) { - return ' - <div class="centre"> - <input type="button" disabled name="None" value="'. $msg . '" /> - </div>'; -} + echo '<tr><td>' . _('To Inventory Category Code'). ':</td> + <td><select name="ToCriteria">'; -/** - * This access to item data includes its price. - * The routine works in two contexts: when only the category is given - * it looks for all the items - */ -function getStockItems($CategoryID, $CurrCode, $SalesType, $EffectiveDate, $StockID=false) { - global $db, $Today; + /*Set the index for the categories result set back to 0 */ + DB_data_seek($CatResult,0); - if ($StockID!==false) { - $WhereClause = "stockmaster.stockid='$StockID' LIMIT 1"; - } else { - $WhereClause = "stockmaster.categoryid='$CategoryID' ORDER BY stockmaster.stockid"; - } - - $WhereClause = " stockmaster.discontinued!=1 AND " . $WhereClause; - - $sql="SELECT stockmaster.stockid, - stockmaster.description, - stockmaster.longdescription, - stockmaster.barcode, - prices.price - FROM stockmaster LEFT JOIN prices - ON stockmaster.stockid=prices.stockid - AND prices.currabrev = '" . $CurrCode . "' - AND prices.typeabbrev= '" . $SalesType . "' - AND prices.startdate <= '" . $EffectiveDate . "' - AND (prices.enddate >= '" . $EffectiveDate . "' OR prices.enddate='0000-00-00') - AND prices.debtorno='' - WHERE " . $WhereClause; - - return DB_query($sql, $db); -} - -function getStockData($StockID, $Currency, $salesType, $EffectiveDate) { - $result = getStockItems(null, $Currency, $salesType, $EffectiveDate, $StockID); - return DB_fetch_array($result); -} - -/** - * Change de scale of data given by points - * Returns two array for the dimension and lines of data - */ -function resizeLabel($label) { - global $DimensionTags, $DataTags; - - //<* Values required from the beggining - $scales=array('pt'=>1, 'in'=>72, 'mm'=>(float)72/25.4, 'cm'=>(float)72/2.54); - - $obj = $label->dimensions; - $unit = (string)$obj->Unit; - if ( array_key_exists($unit , $scales) ) { - $factor = $scales[$unit]; - } else { - abortMsg( _('Unit not defined in scale operation! Correct the template') ); - } - - $dims = array(); - foreach ($DimensionTags as $iTag=>$tag) { - if ($tag['type']=='n') // it is a data numeric - $dims[$iTag] = round(((float)$obj->$iTag)*$factor, 3); - elseif ($tag['type']=='i') - $dims[$iTag] = (int)$obj->$iTag; - } - - $obj = $label->data; - $line = array(); - $i=0; - foreach ($obj->line as $labelLine) { - $line[$i] = array(); - foreach ($DataTags as $iTag=>$tag) { - if ($tag['type']=='n') // it is a data numeric - $line[$i][$iTag]= round(((float)$labelLine->$iTag)*$factor, 3); - else - $line[$i][$iTag]=(string)$labelLine->$iTag; // field to use in printing data + While ($myrow = DB_fetch_array($CatResult)){ + echo '<option value="' . $myrow['categoryid'] . '">' . $myrow['categoryid'] . ' - ' . $myrow['categorydescription'] . '</option>'; } - $i++; - } - return array($dims, $line); -} + echo '</select></td></tr>'; -/** - * Returns the following data: - * $Page_Width, - * $Page_Height, - * $Top_Margin, - * $Bottom_Margin, - * $Left_Margin, - * $Right_Margin - */ -function getPageDimensions($dimensions) { - $bm =(float)$dimensions['Sh'] - ( (float)$dimensions['Tm'] + - (int)$dimensions['Rows']*(float)$dimensions['He']); - $rm =(float)$dimensions['Sw'] - ( (float)$dimensions['Lm'] + - (int)$dimensions['Cols']*(float)$dimensions['Wi']); - return array( - (float)$dimensions['Sw'], - (float)$dimensions['Sh'], - (float)$dimensions['Tm'], 0, -// ($bm>0?$bm:0), - (float)$dimensions['Lm'], 0 -// ($rm>0?$rm:0) - ); -} + echo '<tr><td>' . _('For Sales Type/Price List').':</td> + <td><select name="SalesType">'; + $sql = "SELECT sales_type, typeabbrev FROM salestypes"; + $SalesTypesResult=DB_query($sql,$db); -function printLabels($dimensions, $lines, $qtyByItem, $Currency, $salesType, $StockIDList, $EffectiveDate) { - global $pdf, $DecimalPlaces, $Version; - $row = $col = 0; - - $DecimalPlaces=getDecimalPlaces($Currency); - - foreach ($StockIDList as $StockID=>$on) { // At least there is one item - $itemData = getStockData($StockID, $Currency, $salesType, $EffectiveDate); - $num=$qtyByItem; - while ($num-- > 0) { // Print $num labels per item - printStockid($itemData, $dimensions, $lines, $Currency, $row, $col); - if (++$col>=$dimensions['Cols']) { - $col=0; - if (++$row>=$dimensions['Rows']) { - $row=0; - $pdf->newpage(); - } + while ($myrow=DB_fetch_array($SalesTypesResult)){ + if ($_SESSION['DefaultPriceList']==$myrow['typeabbrev']){ + echo '<option selected="selected" value="' . $myrow['typeabbrev'] . '">' . $myrow['sales_type'] . '</option>'; + } else { + echo '<option value="' . $myrow['typeabbrev'] . '">' . $myrow['sales_type'] . '</option>'; } } - } - /* if ($row OR $col) // it seems to be unnecesary. - $pdf->newpage(); */ + echo '</select></td></tr>'; - // now, emit the PDF file (if not errors!) - if ($Version>="3.12") { - $pdf->OutputD($_SESSION['DatabaseName'] . '_Labels_' . date('Y-m-d') . '.pdf');//UldisN - $pdf->__destruct(); //UldisN - } else { - $pdfcode = $pdf->output(); - $len = mb_strlen($pdfcode); + echo '<tr><td>' . _('For Currency').':</td> + <td><select name="Currency">'; + $sql = "SELECT currabrev, country, currency FROM currencies"; + $CurrenciesResult=DB_query($sql,$db); - if ($len<=20){ - return false; - } else{ - header('Content-type: application/pdf'); - header('Content-Length: ' . $len); - header('Content-Disposition: inline; filename=Labels.pdf'); - header('Expires: 0'); - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); - header('Pragma: public'); - - $pdf->Stream(); + while ($myrow=DB_fetch_array($CurrenciesResult)){ + if ($_SESSION['CompanyRecord']['currencydefault']==$myrow['currabrev']){ + echo '<option selected="selected" value="' . $myrow['currabrev'] . '">' . $myrow['country'] . ' - ' .$myrow['currency'] . '</option>'; + } else { + echo '<option value="' . $myrow['currabrev'] . '">' . $myrow['country'] . ' - ' .$myrow['currency'] . '</option>'; + } } - } - return true; // All fine!! -} + echo '</select></td></tr>'; -/*! \brief The heart of the program (perhaps the liver) - * - * It shows the data label from the input $data as update data (id read only) - * if the third parameter is true or a fresh data label (new label). It is - * possible that the combination $data valid and $readonly false occurs when - * invalid data needs to be recaptured because an error in a new label capture. - */ -function printStockid($itemData, $labelDim, $dataParams, $Currency, $row, $col) { - global $pdf, $DecimalPlaces; -//echo $row.':'.$col.'<br />'; - // Calculate the bottom left corner position - $iX = $labelDim['Lm'] + $col * $labelDim['Cw']; - $iY = $labelDim['Sh'] - ($labelDim['Tm'] + ($row+1) * $labelDim['Rh']); + echo '<tr><td>' . _('Effective As At') . ':</td>'; + echo '<td><input type="text" size="11" class="date" alt="' . $_SESSION['DefaultDateFormat'] . '" name="EffectiveDate" value="' . Date($_SESSION['DefaultDateFormat']) . '" />'; + echo '</td></tr>'; - if (isset($_POST['PDFTest'])) { - $pdf->line($iX, $iY+$labelDim['He'], $iX+$labelDim['Wi'], $iY+$labelDim['He']); // top - $pdf->line($iX, $iY, $iX+$labelDim['Wi'], $iY); // bottom - $pdf->line($iX, $iY, $iX, $iY+$labelDim['He']); // left - $pdf->line($iX+$labelDim['Wi'], $iY, $iX+$labelDim['Wi'], $iY+$labelDim['He']); + echo '</table> + <br /> + <div class="centre"> + <input type="submit" name="PrintPDF" value="'. _('Print PDF'). '" /> + </div> + </form>'; } - // Now, for every data, write down the correspondig text - $descrip= $ldescrip=''; - foreach ($dataParams as $line) { - unset($resid); // unlink the previous residue - unset($txt); - $adj='left'; - switch ($line['dat']) { - case 'code': - $txt = $itemData['stockid']; - break; - case 'name1': - $txt = $itemData['description']; - $resid = &$descrip; - break; - case 'name2': - $txt = $descrip; - unset($descrip); - break; - case 'lname1': - $txt = $itemData['longdescription']; - $resid = &$ldescrip; - break; - case 'lname2': - $txt = $ldescrip; - unset($ldescrip); - break; - case 'price': - $txt = locale_number_format($itemData['price'], $DecimalPlaces). ' '. $Currency; -// $adj='left'; - break; - case 'bcode': break; - } - $ix = $iX + $line['pos']; - $iy = $iY + $line['row']; - if (isset($txt)) { - $resid = $pdf->addTextWrap($ix,$iy,$line['max'],$line['font'],$txt, $adj); - } - } -} + include('includes/footer.inc'); -function getDecimalPlaces($Currency) { - global $db; - $sql="SELECT decimalplaces FROM currencies WHERE currabrev='$Currency'"; - $result = DB_query($sql, $db); - if (!DB_num_rows($result)) - abortMsg(_('Couldnt get the currency data')); - $myrow=DB_fetch_row($result); - return $myrow[0]; -} +} /*end of else not PrintPDF */ + ?> Modified: trunk/doc/Change.log =================================================================== --- trunk/doc/Change.log 2012-04-25 06:12:02 UTC (rev 5279) +++ trunk/doc/... [truncated message content] |