function viewResult($echo = false, $no_stats = false) { $_REQUEST->setType('cout', '#^(email|sortedtable)$#'); global $DB, $Controller, $USER; if ($USER->ID == NOBODY) { return false; } if ($_REQUEST['cout']) { $this->sendFile($_REQUEST['cout']); } $_REQUEST->setType('delpost', 'any'); $myPosts = array(); $where = array('id' => $this->ID); if (!$this->mayI(EDIT)) { $myPosts = $DB->formdata->asList(array('id' => $this->ID, 'field_id' => 'poster', 'value' => $USER->ID), 'post_id'); if (!$this->_Public_Form) { if (!$myPosts) { return ''; } $where['post_id'] = $myPosts; } $no_stats = true; } if ($_REQUEST['delpost']) { if ($this->mayI(EDIT) || in_array($_REQUEST['delpost'], $myPosts)) { $DB->formdata->delete(array('id' => $this->ID, 'post_id' => $_REQUEST['delpost']), false); if (!is_null($this->_PostCount)) { --$this->_PostCount; } } } $sort = array(); $r = $DB->formfields->get(array('id' => $this->ID), false, false, 'sort'); while (false !== ($field = Database::fetchAssoc($r))) { $sort[$field['field_id']] = $field['sort']; $fields[$field['field_id']] = $field; $labels[$field['field_id']] = self::fieldlabel($field['label'], $this->loadedLanguage); } asort($sort); $sort = array_flip(array_keys($sort)); $r = $DB->formdata->get($where); $data = array(); $postSort = array(); $u = 0; $stats = array(); while (false !== ($res = Database::fetchAssoc($r))) { if (in_array($res['field_id'], array('poster', 'posted', 'poster:ip', 'language'))) { $postMeta[$res['post_id']][$res['field_id']] = $res['value']; if ($res['field_id'] == 'posted') { $postSort[$res['value']] = $res['post_id']; } } else { if ($this->_Public_Form < 2 && !$this->mayI(EDIT) && !in_array($res['post_id'], $myPosts)) { continue; } if (@in_array($fields[$res['field_id']]['type'], array('Checkbox', 'pCheckbox')) && substr_count($fields[$res['field_id']]['value'], ',') == 0) { if ($res['value']) { $res['value'] = __('Yes'); } else { $res['value'] = __('No'); } } if (!$no_stats) { if (@(!in_array($fields[$res['field_id']]['type'], array('htmlfield', 'textarea', 'hidden', 'mselect')))) { if (isset($stats[$res['field_id']][$res['value']])) { $stats[$res['field_id']][$res['value']]++; } else { $stats[$res['field_id']][$res['value']] = 1; } } elseif ($fields[$res['field_id']]['type'] == 'mselect') { if (!is_array($res['value'])) { $res['value'] = array($res['value']); } foreach ($res['value'] as $sel) { if (isset($stats[$res['field_id']][$sel])) { $stats[$res['field_id']][$sel]++; } else { $stats[$res['field_id']][$sel] = 1; } } } } $data[$res['post_id']][isset($sort[$res['field_id']]) ? $sort[$res['field_id']] : count($sort) + $u++] = new Tablerow(@$labels[$res['field_id']], $res['value']); } } if (empty($postSort)) { return ''; } $sortData = array(); ksort($postSort); foreach ($postSort as $post_id) { if (isset($data[$post_id])) { ksort($data[$post_id]); $sortedData[$post_id] = $data[$post_id]; } else { $sortedData[$post_id] = null; } } $oa = array(); foreach ($sortedData as $post_id => $rows) { $tbl = new Table(new Tableheader(__('Posted by') . ': ' . @$Controller->{$postMeta[$post_id]['poster']}, $this->mayI(EDIT) || in_array($post_id, $myPosts) ? icon('small/delete', __('Delete post'), url(array('delpost' => $post_id), true)) : ''), $rows); $tbl->class = 'form_posterdata'; $oa[] = $tbl; } $output = listify($oa); $_REQUEST->setType('to', 'numeric'); if ($this->mayI(EDIT)) { $output .= '<span class="forminfo">' . $this->PostCount . ' ' . __('posters') . ($this->_Limit ? ' (of ' . $this->_Limit . ')' : '') . '</span>' . '<span class="uform_posterdata"><a href="' . url(array('cout' => 'email'), 'id') . '">' . __('Contact data') . '</a>|<a href="' . url(array('cout' => 'sortedtable'), 'id') . '">' . __('Sorted table') . '</a>' . ($Controller->mailer ? '|<a href="' . url(array('id' => 'mailer', 'to' => $this->ID)) . '">' . __('Email posters') . '</a>' : '') . '</span>'; } if (!$no_stats) { $s = new Table(new Tableheader(__('Field'), __('Data'), __('Occurrances'))); $s->class = 'form_stats_table'; foreach ($stats as $field_id => $values) { $st_rows = array(); $i = 0; foreach ($values as $value => $count) { $st_rows[] = new Tablerow(!$i++ ? @$labels[$field_id] : '', $value, $count); } $s->append($st_rows); } $output .= $s; } if ($echo) { echo $output; } return $output; }
function listEmails($view = false) { global $USER, $Controller, $DB; if ($view == 'new') { $resource = $DB->massmail->get(array('approved' => '0', 'personal' => 'no'), false, false, 'written DESC'); } elseif ($view == 'personal') { $resource = $DB->massmail->get(array('personal' => 'yes'), false, false, 'written DESC'); } else { $resource = $DB->massmail->get(array('approved>' => '0', 'personal' => 'no', 'author' . ($this->mayI(EDIT) ? 'NO_SELECT' : '') => $USER->ID), false, false, 'written DESC'); } $r = ''; if (mysql_num_rows($resource)) { $table = new Table(new Tableheader(__('Author'), __('From'), __('Recipients'), __('Subject'))); $i = 0; while ($email = Database::fetchAssoc($resource)) { $recipients = $Controller->get($email['recipients']); $recs = array(); foreach ($recipients as $re) { $recs[] = $re->link(); } $table->append(new Tablerow($Controller->{$email['author']}->link(), $email['from'] ? $Controller->{$email['from']} : __('Default'), join(', ', $recs), '<a href="' . url(array('eedit' => $email['msg_id']), 'id') . '">' . $email['subject'] . '</a>', '<span class="tools">' . icon($email['sent'] ? 'small/eye' : 'small/email_edit', __($email['sent'] ? 'View' : 'Edit'), url(array('eedit' => $email['msg_id']), 'id')) . icon('small/delete', __('Delete'), url(array('edelete' => $email['msg_id']), 'id')) . ($email['sent'] ? icon('large/network-16', __('Sent')) : ($email['approved'] ? icon('small/tick', __('Approved')) : '')) . '</span>')); } $r .= $table; return $r; } else { return __('Empty'); } }