Exemplo n.º 1
0
 public function __construct($type = 'default')
 {
     PHPWS_Core::initCoreClass('DBPager.php');
     PHPWS_Core::initModClass('faxmaster', 'Fax.php');
     $this->pager = new DBPager('faxmaster_fax', 'Fax');
     $this->pager->setModule('faxmaster');
     $this->pager->setLink('index.php?module=faxmaster');
     // Don't show hidden faxes
     $this->pager->addWhere('hidden', 0);
     // By default, sort the faxes in reverse chronological order
     $this->pager->setOrder('dateReceived', 'DESC', true);
     if ($type == 'archived') {
         $this->pager->setTemplate('archivePager.tpl');
         $this->pager->setEmptyMessage('No archived faxes found.');
         $this->pager->addRowTags('pagerRowTags', 'archived');
         $this->pager->addWhere('archived', 1);
         $this->pager->setSearch('bannerId', 'firstName', 'lastName', 'whichArchive');
     } else {
         $this->pager->setTemplate('faxPager.tpl');
         $this->pager->setEmptyMessage('No faxes found.');
         $this->pager->addRowTags('pagerRowTags');
         $this->pager->addPageTags(array('UNPRINTED_COUNT' => Fax::getUnprintedCount()));
         $this->pager->addWhere('archived', 0);
         $this->pager->setSearch('bannerId', 'firstName', 'lastName');
     }
 }
Exemplo n.º 2
0
 /**
  * Handles the archiving of faxes. Modifies the filesystem by creating new archive files,
  * and remove existing fax files. Has many opportunities to throw exceptions.
  * 
  * Only accessible by URL of form:
  * .../index.php?module=faxmaster&op=archive&start_date=(UNIX TIMESTAMP)[&end_date=(UNIX TIMESTAMP)]
  */
 private function archiveFaxes()
 {
     PHPWS_Core::initModClass('faxmaster', 'Fax.php');
     // Get date range for archive. Use NOW for end date if one is not supplied.
     $startDate = $_REQUEST['start_date'];
     $endDate = isset($_REQUEST['end_date']) ? $_REQUEST['end_date'] : time();
     // Check user's permissions
     if (!Current_User::allow('faxmaster', 'archive')) {
         PHPWS_Core::initModClass('faxmaster', 'exception/PermissionException.php');
         throw new PermissionException('Permission denied');
     }
     // SELECT id FROM faxmaster_fax WHERE dateReceived >= start_date AND dateReceived < end_date AND archived=0;
     $db = new PHPWS_DB('faxmaster_fax');
     $db->addColumn('id');
     $db->addWhere('archived', 0);
     // only grab unarchived files
     $db->addWhere('dateReceived', $startDate, '>=', 'AND');
     // startDate is inclusive
     $db->addWhere('dateReceived', $endDate, '<', 'AND');
     // endDate is exclusive
     $results = $db->select();
     // Make archive
     $path = PHPWS_Settings::get('faxmaster', 'archive_path');
     $archiveName = strftime('%m%d%Y', $startDate) . 'to' . strftime('%m%d%Y', $endDate) . '.tar';
     try {
         $archive = new PharData($path . $archiveName);
     } catch (UnexpectedValueException $e) {
         die('Could not open .tar file' . $e->getMessage());
     } catch (BadMethodCallException $e) {
         die('Bad method call' . $e->getMessage());
     }
     // Fill the archive
     foreach ($results as $result) {
         $fax = new Fax($result['id']);
         try {
             $archive->addFile($fax->getFullPath(), $fax->getFileName());
         } catch (PharException $e) {
             die($e->getMessage());
         }
     }
     // Compress the archive
     try {
         $archive = $archive->compress(Phar::GZ);
     } catch (BadMethodCallException $e) {
         die($e->getMessage());
     }
     // Remove .tar, leaving only the .tar.gz
     unlink($path . $archiveName);
     // Update each fax in the database, then remove it from the fax directory
     foreach ($results as $result) {
         $fax = new Fax($result['id']);
         $fax->setArchived(1, $archiveName . '.gz');
         $fax->save();
         unlink($fax->getFullPath());
     }
 }