1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13: class Hylax_Driver_spandsp extends Hylax_Driver {
14:
15: protected $_states = array();
16: protected $_stat_cols = array();
17: protected $_cmd = array();
18:
19: public function __construct($params)
20: {
21: parent::__construct($params);
22:
23: $this->_states = Hylax::getStates();
24: $this->_stat_cols = Hylax::getStatCols();
25: }
26:
27: public function send($number, $data, $time = null)
28: {
29:
30: $filename = sprintf("%s.fax", Horde::getTempFile('hylax'));
31: $fh = fopen($filename, "w");
32: fwrite($fh, $data);
33: fclose($fh);
34:
35: return $this->createCallFile($filename);
36: }
37:
38: public function createCallFile($filename)
39: {
40: global $conf;
41:
42:
43: $data = sprintf("Channel: %s/%s\n", $conf['fax']['params']['channel'], $number);
44: $data .= sprintf("MaxRetries: %d\n", $conf['fax']['params']['maxretries']);
45: $data .= sprintf("RetryTime: %d\n", $conf['fax']['params']['retrytime']);
46: $data .= sprintf("WaitTime: %d\n", $conf['fax']['params']['waittime']);
47: $data .= sprintf("Application: %s\n", 'txfax');
48: $data .= sprintf("Data: %s|caller\n", $filename);
49:
50: $outfile = sprintf("%s/%s.call", $conf['fax']['params']['outgoing'], strval(new Horde_Support_Uuid()));
51: if ($fh = fopen($outfile, "w")) {
52: fwrite($fh, $data);
53: fclose($fh);
54: return true;
55: }
56:
57: return PEAR::raiseError(sprintf(_("Could not send fax. %s"), $output));
58: }
59:
60: public function numFaxesIn()
61: {
62:
63:
64: }
65:
66: public function numFaxesOut()
67: {
68:
69:
70: }
71:
72: public function getFolder($folder, $path = null)
73: {
74:
75:
76:
77: switch ($folder) {
78: case 'inbox':
79: return array();
80: break;
81:
82: case 'outbox':
83: return array();
84: break;
85:
86: case 'sent':
87: return array();
88: break;
89:
90: case 'archive':
91:
92: return array();
93: break;
94: }
95: }
96:
97: public function getJob($job_id, $folder, $path = null)
98: {
99: global $conf;
100:
101: $job = array();
102:
103: switch ($folder) {
104: case 'inbox':
105: break;
106:
107: case 'outbox':
108:
109:
110: break;
111:
112: case 'sent':
113:
114:
115: break;
116:
117: case 'archive':
118:
119: break;
120: }
121:
122:
123:
124: return $job;
125: }
126:
127: public function getStatus($job_id)
128: {
129: return null;
130: }
131:
132: public function getThumbs($job_id, $ps)
133: {
134: if ($this->_vfs->exists(HYLAX_VFS_PATH, $job_id)) {
135:
136: $images = $this->_vfs->listFolder(HYLAX_VFS_PATH . '/' . $job_id, 'doc.png');
137: if (!empty($images)) {
138: return array_keys($images);
139: }
140: }
141: $images = $this->imagesToVFS($job_id, $ps);
142: return array_keys($images);
143: }
144:
145: public function imagesToVFS($job_id, $ps)
146: {
147: global $conf;
148:
149: $this->_vfs->autoCreatePath(HYLAX_VFS_PATH . '/' . $job_id);
150:
151: $ps = '/var/spool/fax/' . $ps;
152: $vfs_path = $conf['vfs']['params']['vfsroot'] . '/' . HYLAX_VFS_PATH;
153:
154: $cmd = sprintf('convert -geometry 25%% %s %s/%s/thumb.png', $ps, $vfs_path, $job_id);
155: $result = $this->_exec($cmd);
156:
157: $cmd = sprintf('convert %s %s/%s/doc.png', $ps, $vfs_path, $job_id);
158: $result = $this->_exec($cmd);
159:
160:
161: return $this->_vfs->listFolder(HYLAX_VFS_PATH . '/' . $job_id, 'doc.png');
162: }
163:
164: protected function _exec($cmd, $input = '')
165: {
166: $spec = array(
167: 1 => array('pipe', 'w'),
168: 2 => array('file', '/tmp/error-output.txt', 'a')
169: );
170: $proc = proc_open($this->_params['base_path'] . $cmd, $spec, $pipes);
171:
172:
173: while (!feof($pipes[1])) {
174: $result[] = trim(fgets($pipes[1], 1024));
175: }
176: @fclose($pipes[1]);
177: @fclose($pipes[2]);
178: proc_close($proc);
179:
180: if (empty($result[(count($result) - 1)])) {
181: unset($result[(count($result) - 1)]);
182: }
183:
184: return $result;
185: }
186:
187: }
188: