[828] | 1 | <?php |
---|
| 2 | |
---|
| 3 | if (stristr($_SERVER['REQUEST_URI'], ".inc.php")) die("no access"); |
---|
| 4 | |
---|
| 5 | $base_path="."; |
---|
| 6 | $base_auth = "ADMINISTRATION_AUTH"; |
---|
| 7 | $base_title = "\$msg[7]"; |
---|
| 8 | $class_path= "./classes"; |
---|
| 9 | $include_path= "./includes"; |
---|
| 10 | |
---|
| 11 | //---------------------LLIUREX 12/02/2015 ------------------------- |
---|
| 12 | require_once ("$base_path/includes/init.inc.php"); |
---|
| 13 | //--------------------- FIN LLIUREX 12/02/2015 ------------------------- |
---|
| 14 | require_once("$class_path/notice.class.php"); |
---|
| 15 | require_once("$class_path/expl.class.php"); |
---|
| 16 | require_once("$class_path/indexint.class.php"); |
---|
| 17 | require_once("$include_path/notice_authors.inc.php"); |
---|
| 18 | require_once("$include_path/notice_categories.inc.php"); |
---|
| 19 | require '/usr/share/php/fpdf/fpdf.php'; |
---|
| 20 | |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | define(CONVERSION,(1/25.4));//Conversión inch/mm |
---|
| 24 | define(COLS_PER_PAGE, 3); // Nº columnas por página |
---|
| 25 | define(ROWS_PER_PAGE, 8); // Nº filas por página |
---|
| 26 | define(BARCODE_HEIGHT, 54); // en pixels |
---|
| 27 | define(BARCODE_WIDTH, 175); // en pixels |
---|
| 28 | define(ALIGN, 'C'); |
---|
| 29 | define(LABEL_WIDTH, (70.8*CONVERSION)); // en mm |
---|
| 30 | define(LABEL_HEIGHT, (36.5*CONVERSION)); // en mm |
---|
| 31 | define(H_MARGIN, (7*CONVERSION)); // horizontal (izquierda y derecha) margenes de la pagina, en mm |
---|
| 32 | define(V_MARGIN, (12*CONVERSION)); // vertical (top & bottom) margins of page, in mm |
---|
| 33 | |
---|
| 34 | //define(SPACE_BETWEEN_LABELS, ($parametros["SPACE_BETWEEN_LABELS"])*CONVERSION); // espacio horizontal entre etiquetas |
---|
| 35 | //define(SPACE_BETWEEN_LABELS_VERTICAL, ($parametros["SPACE_BETWEEN_LABELS_VERTICAL"])*CONVERSION); // espacio vertical entre etiquetas |
---|
| 36 | |
---|
| 37 | function f_rellena_ceros($as_dato) { |
---|
| 38 | if(strlen($as_dato)>0 && strlen($as_dato)<9){ |
---|
| 39 | for($i=strlen($as_dato); $i<9; $i++) |
---|
| 40 | $as_dato="0".$as_dato;} |
---|
| 41 | |
---|
| 42 | return $as_dato; |
---|
| 43 | |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | function str_squeeze($test) { |
---|
| 47 | return trim(ereg_replace( ' +', '', $test)); |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | $codigos=$_GET['codigos']; |
---|
| 51 | //$codigos=str_replace(" ", "", $codigos); |
---|
| 52 | |
---|
| 53 | |
---|
| 54 | switch ($codigos){ |
---|
| 55 | |
---|
| 56 | case '':{ |
---|
| 57 | //---------------------LLIUREX 12/02/2015 ------------------------- |
---|
| 58 | //require_once ("$base_path/includes/init.inc.php"); |
---|
| 59 | //---------------------FIN LLIUREX 12/02/215 ---------------------- |
---|
| 60 | echo "<center><form class='form-admin' name='form2' ENCTYPE=\"multipart/form-data\" method='get' action=\"./tejuelo.php?codigos=\".$codigos·\"\"><b>$msg[tejuelo] </b><input name='codigos' accept='text/plain' type='text' size='80'><input align='center' type='button' name='continuar' value='Continuar' onclick='form.submit()'></form></center>"; |
---|
| 61 | break;} |
---|
| 62 | |
---|
| 63 | |
---|
| 64 | |
---|
| 65 | default:{ |
---|
| 66 | $matriz=array(); |
---|
| 67 | $base_noheader = 1; |
---|
| 68 | |
---|
| 69 | |
---|
| 70 | $codigos=str_squeeze($codigos); |
---|
| 71 | |
---|
| 72 | if((strpos($codigos, ",")!== false)) $aux=explode(",",$codigos); |
---|
| 73 | else $aux=$codigos; |
---|
| 74 | |
---|
| 75 | require("$base_path/includes/db_param.inc.php"); |
---|
| 76 | |
---|
| 77 | $link2 = @mysql_connect(SQL_SERVER, USER_NAME, USER_PASS) OR die("Error MySQL"); |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | if (is_array($aux)) { |
---|
| 81 | foreach ($aux as $codi) { |
---|
| 82 | if(strpos($codi, "-") === false && strlen($codi) <= 9 ){ |
---|
| 83 | if (is_numeric($codi)) $matriz[]= (int) $codi; |
---|
| 84 | else $matriz[]= $codi; |
---|
| 85 | } |
---|
| 86 | else if (strpos($codi, "-") !== false) { |
---|
| 87 | $aux2=explode("-",$codi); |
---|
| 88 | if ( is_numeric($aux2[0]) && is_numeric($aux2[1]) ) { |
---|
| 89 | $aux2[0]= (int) $aux2[0]; |
---|
| 90 | $aux2[1]= (int) $aux2[1]; |
---|
| 91 | while($aux2[0] <= $aux2[1]){ |
---|
| 92 | if (strlen($aux2[0]) <= 9) $matriz[] = (int) $aux2[0]; |
---|
| 93 | $aux2[0]++; |
---|
| 94 | } |
---|
| 95 | } |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | } |
---|
| 99 | } |
---|
| 100 | elseif ($aux === "*"){ |
---|
| 101 | $q ='SELECT expl_cb FROM exemplaires'; |
---|
| 102 | |
---|
| 103 | $resultData = @mysql_query($q, $link2); |
---|
| 104 | if (@mysql_num_rows($resultData) != 0) { |
---|
| 105 | |
---|
| 106 | while ($rowData = mysql_fetch_array($resultData)) { |
---|
| 107 | if (strlen($rowData['expl_cb']) <= 9) $matriz[]= $rowData['expl_cb']; |
---|
| 108 | } |
---|
| 109 | } |
---|
| 110 | mysql_free_result($resultData); |
---|
| 111 | } |
---|
| 112 | else { |
---|
| 113 | if(strpos($aux, "-") === false && strlen($aux) <= 9 ){ |
---|
| 114 | if (is_numeric($aux)) $matriz[]= (int) $aux; |
---|
| 115 | else $matriz[]= $aux; |
---|
| 116 | } |
---|
| 117 | else if (strpos($aux, "-") !== false) { |
---|
| 118 | $aux2=explode("-",$aux); |
---|
| 119 | if ( is_numeric($aux2[0]) && is_numeric($aux2[1]) ) { |
---|
| 120 | $aux2[0]= (int) $aux2[0]; |
---|
| 121 | $aux2[1]= (int) $aux2[1]; |
---|
| 122 | while($aux2[0] <= $aux2[1]){ |
---|
| 123 | if (strlen($aux2[0]) <= 9) $matriz[] = (int) $aux2[0]; |
---|
| 124 | $aux2[0]++; |
---|
| 125 | } |
---|
| 126 | } |
---|
| 127 | } |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | $size = count($matriz); |
---|
| 131 | |
---|
| 132 | //Determinamos margenes de los barcode |
---|
| 133 | $barcode_h_margin = ((LABEL_WIDTH-(BARCODE_WIDTH/72))/2); |
---|
| 134 | $barcode_v_margin = ((LABEL_HEIGHT-(BARCODE_HEIGHT/72))/2); |
---|
| 135 | |
---|
| 136 | // Creamos objeto PDF |
---|
| 137 | |
---|
| 138 | $pdf=new FPDF('P','in','A4'); |
---|
| 139 | |
---|
| 140 | // Metadata |
---|
| 141 | $pdf->SetAuthor('Lliurex'); |
---|
| 142 | $pdf->SetTitle('Tejuelo Lliurex'); |
---|
| 143 | |
---|
| 144 | //Otras características |
---|
| 145 | $pdf->SetDisplayMode('real'); // Mostramos el zoom al 100% |
---|
| 146 | |
---|
| 147 | // Añadimos una pagina al documento PDF |
---|
| 148 | $pdf->AddPage(); |
---|
| 149 | |
---|
| 150 | // Fijamos los márgenes |
---|
| 151 | $pdf->SetMargins(H_MARGIN, V_MARGIN); |
---|
| 152 | |
---|
| 153 | // Manejamos nosotros cuando la pagina debe acabar |
---|
| 154 | $pdf->SetAutoPageBreak(false); |
---|
| 155 | $pdf->AddFont('barcode', '', "barcode.php"); |
---|
| 156 | $y = V_MARGIN; //Esta variable sigue la posición y (vertical) |
---|
| 157 | $x = H_MARGIN; // Nueva fila, reseteamos x-position |
---|
| 158 | |
---|
| 159 | |
---|
| 160 | $new_row=1; |
---|
| 161 | $new_col=1; |
---|
| 162 | |
---|
| 163 | |
---|
| 164 | foreach ($matriz as $exe_cote) { |
---|
| 165 | |
---|
| 166 | if (is_numeric($exe_cote)) { |
---|
| 167 | $q ='SELECT expl_cote, expl_cb FROM exemplaires WHERE expl_cb='.f_rellena_ceros($exe_cote).''; |
---|
| 168 | }else { |
---|
| 169 | $q ='SELECT expl_cote, expl_cb FROM exemplaires WHERE expl_cb=\''.$exe_cote.'\''; |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | //if ((strlen($exe_cote)==9) || $all == true){ |
---|
| 173 | $resultData = @mysql_query($q, $link2); |
---|
| 174 | |
---|
| 175 | if (@mysql_num_rows($resultData) != 0) { |
---|
| 176 | |
---|
| 177 | //Recuperamos los datos de cada solicitud confirmada |
---|
| 178 | |
---|
| 179 | while ($rowData = mysql_fetch_array($resultData)) { |
---|
| 180 | |
---|
| 181 | //dato cote |
---|
| 182 | |
---|
| 183 | $cote=$rowData['expl_cote']; |
---|
| 184 | if (is_numeric($exe_cote)) { |
---|
| 185 | if (is_numeric($rowData['expl_cb'])) { |
---|
| 186 | if ((int) $exe_cote === (int) $rowData['expl_cb']) $cb=(int)$rowData['expl_cb']; |
---|
| 187 | else continue; |
---|
| 188 | } else continue; |
---|
| 189 | } else $cb=$rowData['expl_cb']; |
---|
| 190 | |
---|
| 191 | |
---|
| 192 | if ($new_row > 8) // Nueva pagina, reseteamos x-position |
---|
| 193 | { |
---|
| 194 | |
---|
| 195 | // Creamos una nueva pagina |
---|
| 196 | $pdf->AddPage(); |
---|
| 197 | $pdf->SetMargins(H_MARGIN, V_MARGIN); |
---|
| 198 | $pdf->SetAutoPageBreak(false); |
---|
| 199 | $y = V_MARGIN; |
---|
| 200 | $x = H_MARGIN; |
---|
| 201 | $new_row=1; |
---|
| 202 | $new_col=1; |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | $matriz2=explode(" ",$cote); |
---|
| 206 | $pdf->SetFont('Arial','B',10); |
---|
| 207 | $pdf->SetY($y); |
---|
| 208 | $pdf->SetX($x); |
---|
| 209 | if (strlen($matriz2[0])>6) $align=""; |
---|
| 210 | else $align="C"; |
---|
| 211 | $pdf->Cell(LABEL_WIDTH/5, ($barcode_v_margin*1),$matriz2[0],"LT", 0, $align); |
---|
| 212 | $pdf->Cell(LABEL_WIDTH-1, ($barcode_v_margin*1),"","TR", 0,'C'); |
---|
| 213 | $pdf->Ln(); |
---|
| 214 | $pdf->SetX($x); |
---|
| 215 | $pdf->Cell(LABEL_WIDTH/5, ($barcode_v_margin*1),$matriz2[1],"L", 0,'C'); |
---|
| 216 | $pdf->setFont('barcode',"",25); |
---|
| 217 | $pdf->Cell(LABEL_WIDTH-1, ($barcode_v_margin*1),"*".f_rellena_ceros($cb)."*","R", 0,'C'); |
---|
| 218 | $pdf->SetFont('Arial','B',10); |
---|
| 219 | $pdf->Ln(); |
---|
| 220 | $pdf->SetX($x); |
---|
| 221 | $pdf->Cell(LABEL_WIDTH/5, ($barcode_v_margin*1),$matriz2[2],"LB", 0,'C'); |
---|
| 222 | $pdf->Cell(LABEL_WIDTH-1, ($barcode_v_margin*1),f_rellena_ceros($cb),"BR", 0,'C'); |
---|
| 223 | |
---|
| 224 | if (($new_col%COLS_PER_PAGE)==0) { |
---|
| 225 | $x = H_MARGIN; |
---|
| 226 | $y += LABEL_HEIGHT-0.03; |
---|
| 227 | $new_row++; |
---|
| 228 | $new_col=1; |
---|
| 229 | } else { |
---|
| 230 | $new_col++; |
---|
| 231 | $x += LABEL_WIDTH-0.10; |
---|
| 232 | } |
---|
| 233 | |
---|
| 234 | |
---|
| 235 | } |
---|
| 236 | @mysql_free_result($resultData); |
---|
| 237 | |
---|
| 238 | }else continue; |
---|
| 239 | //} else continue; |
---|
| 240 | |
---|
| 241 | } |
---|
| 242 | |
---|
| 243 | |
---|
| 244 | |
---|
| 245 | // Desconexión de la Base de Datos |
---|
| 246 | mysql_close(); |
---|
| 247 | |
---|
| 248 | // Limpiar (ELIMINAR) el búfer de salida y Deshabilitar el Almacenamiento en El Mismo -12/02/2015 |
---|
| 249 | ob_end_clean(); |
---|
| 250 | |
---|
| 251 | $pdf->Output('tejuelo.pdf', 'D'); // Salida es un pdf descargable |
---|
| 252 | |
---|
| 253 | |
---|
| 254 | } |
---|
| 255 | |
---|
| 256 | |
---|
| 257 | } |
---|
| 258 | ?> |
---|