Overview

Packages

  • Hylax
  • None

Classes

  • Hylax
  • Hylax_Driver
  • Hylax_Driver_hylafax
  • Hylax_Driver_spandsp
  • Hylax_Image
  • Hylax_SQL_Attributes
  • Hylax_Storage
  • Hylax_Storage_sql
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Hylax_Driver_spandsp Class
  4:  *
  5:  * Copyright 2005-2012 Horde LLC (http://www.horde.org/)
  6:  *
  7:  * See the enclosed file COPYING for license information (GPL). If you
  8:  * did not receive this file, see http://www.horde.org/licenses/gpl.
  9:  *
 10:  * @author  Joel Vandal <joel@scopserv.com>
 11:  * @package Hylax
 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:         /* Create a temporary file. */
 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:         /* Create outgoing call */
 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:         //$inbox = $this->getInbox();
 63:         //return count($inbox);
 64:     }
 65: 
 66:     public function numFaxesOut()
 67:     {
 68:         //$outbox = $this->getOutbox();
 69:         //return count($outbox);
 70:     }
 71: 
 72:     public function getFolder($folder, $path = null)
 73:     {
 74:         // FIXME: This method is intended to return an array of items in the
 75:         // specified folder.
 76:         // Need to figure out how to make this work with SpanDSP.
 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:             //return $GLOBALS['storage']->getFolder($path);
 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:             // $filename = '/var/spool/fax/sendq/q' . $job_id;
109:             // $job = $this->_getParseSendJob($filename);
110:             break;
111: 
112:         case 'sent':
113:             // $filename = '/var/spool/fax/doneq/q' . $job_id;
114:             // $job = $this->_getParseSendJob($filename);
115:             break;
116: 
117:         case 'archive':
118:             //return $GLOBALS['storage']->getFolder($path);
119:             break;
120:         }
121: 
122:         // $job['thumbs'] = $this->getThumbs($job_id, 'docq/' . $job['postscript'], true);
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:             /* Return thumb image list. */
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:         /* Do thumbs. */
154:         $cmd = sprintf('convert -geometry 25%% %s %s/%s/thumb.png', $ps, $vfs_path, $job_id);
155:         $result = $this->_exec($cmd);
156:         /* Do full images. */
157:         $cmd = sprintf('convert %s %s/%s/doc.png', $ps, $vfs_path, $job_id);
158:         $result = $this->_exec($cmd);
159: 
160:         /* Return thumb image list. */
161:         return $this->_vfs->listFolder(HYLAX_VFS_PATH . '/' . $job_id, 'doc.png');
162:     }
163: 
164:     protected function _exec($cmd, $input = '')
165:     {
166:         $spec = array(//0 => array('pipe', 'r'),
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:         //fwrite($pipes[0], $input);
172:         //@fclose($pipes[0]);
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: 
API documentation generated by ApiGen