diff --git a/calls/call_document_merge_rosters.class.php b/calls/call_document_merge_rosters.class.php index 1fd18977..0ad42724 100644 --- a/calls/call_document_merge_rosters.class.php +++ b/calls/call_document_merge_rosters.class.php @@ -1,21 +1,34 @@ ', trim($item)); + } elseif ($extension == 'odt'){ + $s = str_replace("\n", '', trim($item)); + } else { + $s = trim($item); + } + $s = str_replace('&','&',$s); + return $s; + + } + function run() { $roster_id = (int)array_get($_REQUEST, 'roster_view'); if (empty($roster_id)) return; - $file_info = array_get($_FILES, 'source_document'); - $content = null; - if (empty($file_info['tmp_name'])) { - trigger_error('Template file does not seem to have been uploaded'); - return; - } - $extension = @strtolower(end(explode('.', $file_info['name']))); - $source_file = $file_info['tmp_name']; - rename ($source_file, $source_file.'.'.$extension); - $source_file = $source_file.'.'.$extension; - switch ($extension) { + + $this->GetTemplate(); + + switch ($this->extension) { case 'odt': case 'odg': case 'ods': @@ -25,6 +38,7 @@ function run() case 'docx': case 'xlsx': case 'ppt': + case self::SHOWKEYWORDS: $view = $GLOBALS['system']->getDBObject('roster_view', $roster_id); $start_date = substr(array_get($_REQUEST, 'start_date', ''), 0, 10); $end_date = substr(array_get($_REQUEST, 'end_date', ''), 0, 10); @@ -32,6 +46,7 @@ function run() $labels = array(); $roster = array(); $people = array(); + $persons_unique = array(); $rowno = 0; foreach ($data as $row) { switch ($rowno) { @@ -42,7 +57,7 @@ function run() $rowno++; $itemno = 0; foreach ($row as $item) { - $labels['label'.$itemno] = $item; + $labels['label'.$itemno] = str_replace('&','&',$item); $itemno++; } for ($i = 0; $i > 20; $i++) { @@ -53,20 +68,44 @@ function run() default: $rowno++; $itemno = 0; + $roleno = 1; $roster_row = array(); $persons = array(); foreach ($row as $item) { - $roster_row['role'.$itemno] = str_replace("\n", ', ', $item); - if ($itemno == 0) { - $roster_row['date'] = $item; - $date = $item; - } else { - $hashes = explode("\n", $item); - foreach ($hashes as $hash) { - $persons[$hash] = 1; - } + switch ($itemno) { + case 0: + $roster_row['date'] = $item; + $date = $item; + $itemno++; + break; + case 1: + $roster_row['format'] = $item; + $itemno++; + break; + case 2: + $roster_row['topic'] = trim($item); + $title = $roster_row['topic']; + $itemno++; + break; + case 3: + $roster_row['notes'] = $item; + $roster_row['notes_cr'] = $this->NewLines($this->extension, $item); + $itemno++; + break; + case 4: + $roster_row['comment'] = $item; + $itemno++; + break; + default: + $roster_row['role'.$roleno] = str_replace('&','&',str_replace("\n", ', ', $item)); + $roster_row['role_cr'.$roleno] = $this->NewLines($this->extension, $item); + $hashes = explode("\n", $item); + foreach ($hashes as $hash) { + $persons[$hash] = 1; + } + $itemno++; + $roleno++; } - $itemno++; } for ($i = 0; $i > 20; $i++) { $labels['role'.$itemno] = ''; @@ -75,41 +114,73 @@ function run() $roster[] = $roster_row; $peoples = array(); foreach ($persons as $key => $value) { - $peoples[] = $key; + if (trim($key) <> '') { + $peoples[] = trim($key); + } } asort($peoples); foreach ($peoples as $value) { - $people[] = array('date' => $date, 'name' => $value); + $people[] = array('date' => $date, 'name' => str_replace('&','&',$value)); + $persons_unique[trim(str_replace('&','&',$value))] = $value; } break; } } - require_once 'include/tbs.class.php'; - include_once 'include/tbs_plugin_opentbs.php'; - if (ini_get('date.timezone')=='') { - date_default_timezone_set('UTC'); - } - $TBS = new clsTinyButStrong; - $TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN); - $TBS->SetOption('noerr', TRUE); - $TBS->LoadTemplate($source_file, OPENTBS_ALREADY_UTF8); - $TBS->ResetVarRef(false); - $TBS->VarRef['system_name'] = ifdef('SYSTEM_NAME', ''); - $TBS->VarRef['timezone'] = ifdef('TIMEZONE', ''); - $TBS->VarRef['username'] = $_SESSION['user']['username']; - $TBS->VarRef['first_name'] = $_SESSION['user']['first_name']; - $TBS->VarRef['last_name'] = $_SESSION['user']['last_name']; - $TBS->VarRef['email'] = $_SESSION['user']['email']; + $person = array(); + asort($persons_unique); + foreach ($persons_unique as $key => $value) { + $person[] = array('name' => $key); + } + + if ($this->ShowKeywords) { + $this->Keyword('roster_view_name', $_REQUEST['roster_view_name']); + $this->Keyword('date', $date); + $this->Keyword('title', $title); + $this->Keyword(); + $this->KeywordSection('person'); + foreach ($person as $line) { + foreach ($line as $k => $v) { + $this->Keyword($k, $v); + } + } + $this->Keyword(); + $this->KeywordSection('labels'); + foreach ($labels as $k => $v) { + $this->Keyword($k, $v); + } + $this->Keyword(); + $this->KeywordSection('roster'); + foreach ($roster as $line) { + foreach ($line as $k => $v) { + $this->Keyword($k, $v); + } + $this->Keyword(); + } + $this->Keyword(); + $this->KeywordSection('people'); + foreach ($people as $line) { + foreach ($line as $k => $v) { + $this->Keyword($k, $v); + } + $this->Keyword(); + } + + $this->_printKeywordList(); + return; + } + + $TBS = $this->newTBS(); $TBS->VarRef['roster_view_name'] = $_REQUEST['roster_view_name']; $TBS->VarRef['date'] = $date; + $TBS->VarRef['title'] = $title; $TBS->MergeBlock('labels', array($labels)); $TBS->MergeBlock('roster', $roster); $TBS->MergeBlock('people', $people); - $filename = basename($file_info['name']); - $TBS->Show(OPENTBS_DOWNLOAD, $filename); + $TBS->MergeBlock('person', $person); + $this->downloadTBS($TBS); break; default: - trigger_error("Format $extension not yet supported"); + trigger_error("Format $this->extension not yet supported"); return; } } diff --git a/db_objects/roster_view.class.php b/db_objects/roster_view.class.php index 54a83862..10c3ad36 100644 --- a/db_objects/roster_view.class.php +++ b/db_objects/roster_view.class.php @@ -416,7 +416,8 @@ public function printCSV($start_date=NULL, $end_date=NULL, $return=FALSE) $dummy_service = new Service(); if (empty($start_date)) $start_date = date('Y-m-d'); - $service_params = Array('congregationid' => $this->getCongregations(), '>date' => date('Y-m-d', strtotime($start_date.' -1 day'))); + $Congregations = $this->getCongregations(); + $service_params = Array('congregationid' => $Congregations, '>date' => date('Y-m-d', strtotime($start_date.' -1 day'))); if (!empty($end_date)) $service_params['getDBObjectData('service', $service_params, 'AND', 'date'); @@ -457,9 +458,38 @@ public function printCSV($start_date=NULL, $end_date=NULL, $return=FALSE) } } $csvData[] = $row; - + $to_print[$service_details['date']]['service'][$service_details['congregationid']] = $service_details; foreach ($to_print as $date => $ddetail) { $row = Array(format_date($date)); + if ($return) { + $row['format'] = ''; + $row['topic'] = ''; + $row['notes'] = ''; + $row['comments'] = ''; + foreach ($Congregations as $i) { + if (isset($ddetail['service'][$i]['format_title'])) { + $row['format'] = $ddetail['service'][$i]['format_title']; + } + if (isset($ddetail['service'][$i]['topic_title'])) { + $row['topic'] = $ddetail['service'][$i]['topic_title']; + } + if (trim(strval($row['topic'])) == '
1) { + $row['notes'] = ''; + } + } foreach ($this->_members as $id => $mdetail) { if (empty($mdetail)) continue; diff --git a/views/view_7_rosters__1_display_roster_assignments.class.php b/views/view_7_rosters__1_display_roster_assignments.class.php index 0086c61d..743aa55f 100644 --- a/views/view_7_rosters__1_display_roster_assignments.class.php +++ b/views/view_7_rosters__1_display_roster_assignments.class.php @@ -117,48 +117,68 @@ function _printParams() if (PUBLIC_ROSTER_SECRET) $url .= '&secret='.PUBLIC_ROSTER_SECRET; echo 'View in public site   '; } - - require_once 'size_detector.class.php'; - if (!SizeDetector::isNarrow()) { - ?> - - Download... - - - '; + echo 'Download CSV   '; + ?> + Merge a document... - if (!SizeDetector::isNarrow()) { - ?> -