function _processPopulate()
 {
     $newDir = $this->_filename . '/' . $this->_service_date;
     if (!is_dir($newDir)) {
         mkdir($newDir);
     }
     chdir($this->_filename);
     $this->_replacements = $_POST['replacements'];
     foreach (self::getCongregations() as $congid => $cong) {
         foreach (explode(',', self::EXTENSIONS) as $ext) {
             $thisFile = $this->_filename . '/' . $cong['meeting_time'] . '.' . $ext;
             if (is_file($thisFile)) {
                 $newFile = $newDir . '/' . basename($thisFile);
                 if (file_exists($newFile)) {
                     if (!unlink($newFile)) {
                         trigger_error('Cannot write to ' . $newFile . ' - is the file in use?');
                         continue;
                     }
                 }
                 copy($thisFile, $newFile);
                 if ($p = fileperms($thisFile)) {
                     chmod($newFile, $p);
                 }
                 //if (in_array('SERVICE_CONTENT', $this->_keywords)) {
                 $service = Service::findByDateAndCong($this->_service_date, $congid);
                 if ($service) {
                     ob_start();
                     $service->printServiceContent();
                     $html = ob_get_clean();
                     if ($html) {
                         ODF_Tools::insertHTML($newFile, $html, '%SERVICE_CONTENT%');
                     }
                 }
                 //}
                 ODF_Tools::replaceKeywords($newFile, $this->_replacements[$congid]);
                 $this->_generated_files[$newFile] = self::_cleanDirName($newDir) . ' / ' . basename($newFile);
             }
         }
     }
 }
 function expandFile($filename)
 {
     $pathinfo = pathinfo($filename);
     $new_dirname = $pathinfo['dirname'] . '/' . $this->_service_date;
     if (!file_exists($new_dirname)) {
         mkdir($new_dirname);
     }
     if (is_writable($new_dirname)) {
         chdir($new_dirname);
         foreach ($this->_congregations as $congid => $cong) {
             $new_filename = substr($pathinfo['basename'], 0, -(strlen($pathinfo['extension']) + 1)) . '_' . $cong['meeting_time'] . '.' . $pathinfo['extension'];
             if (file_exists($new_filename)) {
                 if (!unlink($new_filename)) {
                     trigger_error("Could not overwrite " . $new_filename . ' - file open?');
                     continue;
                 }
             }
             copy($filename, $new_filename);
             ODF_Tools::replaceKeywords($new_filename, array_get($_POST['replacements'], $congid, array()));
             chmod($new_filename, fileperms($filename));
             $this->_generated_files[] = basename($pathinfo['dirname']) . ' / ' . basename($new_dirname) . ' / ' . $new_filename;
         }
     }
 }