-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmailing_label.module
118 lines (99 loc) · 2.73 KB
/
mailing_label.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
// $Id: mailing_label.module,v 1.4.2.5 2009/10/25 02:05:08 acouch Exp $
$mailing_label_forms = array();
/**
* Implementation of hook_views_api().
*
*/
function mailing_label_views_api(){
return array(
'api' => 2,
);
}
/**
* Implementation of hook_forms().
*
* This is necessary when multiple mailing_label forms appear on the same page, each
* requiring a separate form_id, but all using the same underlying callbacks.
*/
function mailing_label_forms($form_id, $args) {
global $mailing_label_forms;
if (strpos($form_id, 'mailing_label_form_') !== FALSE) {
$mailing_label_forms[$form_id] = array('callback' => 'mailing_label_form', 'callback arguments' => $args);
return $mailing_label_forms;
}
}
/**
* Implementation of hook_form().
*
*/
function mailing_label_form($form_state, $results) {
$options = array('5160' => t('Avery 5160'),
'5161' => t('Avery 5161'),
'5162' => t('Avery 5162'),
'5163' => t('Avery 5163'),
'8600' => t('Avery 8600'),
'L7160' => t('Avery L7160'),
'L7161' => t('Avery L7161'),
'L7163' => t('Avery L7163'),
);
$form['choices'] = array(
'#type' => 'select',
'#title' => t('Select a mailing label size'),
'#options' => $options,
'#tree' => TRUE,
);
$form['description'] = array (
'#type' => 'hidden',
'#tree' => $results,
);
$form['submit'] = array('#type' => 'submit', '#value' => t('Print PDF'));
$form['#submit'] = array('mailing_label_form_submit',);
$form['#validate'][] = 'mailing_label_form_validate';
return $form;
}
/**
* Implementation of hook_form_validate().
*
*/
function mailing_label_form_validate($form, &$form_state){
}
/**
* Implementation of hook_form_submit().
*
*/
function mailing_label_form_submit($form, &$form_state) {
$results = $form['description']['#tree'];
$format = $form_state['values']['choices'];
mailing_label_create_label($results, $format);
}
/**
* Call hook_form().
*
*/
function mailing_label_pdf_form($results,$view) {
return drupal_get_form('mailing_label_form_'.$view,$results);
}
/**
* Create label function
*
*/
function mailing_label_create_label(&$contactRows, &$format) {
$path = drupal_get_path('module', 'mailing_label');
require_once ($path . '/mailing_label-ufpdf.php');
$pdf = new Mailing_Label_PDF_Label($format,'mm');
$pdf->Open();
$pdf->AddFont('DejaVu Sans', '', 'DejaVuSans.php');
$pdf->SetFont('DejaVu Sans');
//build contact string that needs to be printed
$val = null;
foreach ($contactRows as $row => $value) {
foreach ($value as $k => $v) {
$val.=$v;
}
$pdf->AddPdfLabel($val);
$val = '';
}
$pdf->Output( 'label_' . $format . '.pdf', 'D' );
exit;
}