Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
ipb_poll_edit_fns.inc
1 <?php
18 require_once SQ_INCLUDE_PATH.'/asset_edit/asset_edit_fns.inc';
19 
32 {
33 
34 
39  function Ipb_Poll_Edit_Fns()
40  {
41  $this->Asset_Edit_Fns();
42 
43  $this->static_screens = Array(
44  'details' => Array(
45  'name' => 'Details',
46  'force_unlock' => TRUE,
47  'lock_type' => 'none',
48  ),
49  'dependants' => Array(
50  'name' => 'Dependants',
51  'force_unlock' => TRUE,
52  'lock_type' => 'none',
53  ),
54  );
55 
56  }//end constructor
57 
58 
69  function paintPoll(&$asset, &$o, $prefix)
70  {
71 
72  if ($asset->_suffix == '0') {
73  $ipb_bridge =& $GLOBALS['SQ_SYSTEM']->am->getAsset($asset->_ipbid, 'ipb_bridge');
74  $ipb =& $ipb_bridge->getIpbConn();
75  $list_of_polls = $ipb->getListOfPolls();
76 
77  if (empty($list_of_polls)) {
78  $o->openField(translate('list_of_polls'));
79  echo translate('no_poll_in_forum');
80  $o->closeField();
81  } else {
82  $o->openSection(translate('summary'));
83  $o->openField(translate('num_of_polls'));
84  echo count($list_of_polls);
85  $o->closeField();
86 
87  $o->openField(translate('list_of_polls'));
88  $ipb =& $ipb_bridge->getIpbConn();
89  ?>
90  <table class="sq-backend-table">
91  <tr>
92  <th style="width: 45%"><?php echo translate('question'); ?></th>
93  <th style="width: 50%"><?php echo translate('asset'); ?></th>
94  <th style="width: 15%"><?php echo translate('state'); ?></th>
95  </tr>
96  <?php
97  foreach ($list_of_polls as $poll) {
98  $data = $ipb->getTopicInfo($ipb_bridge->id.':'.'t_'.$poll['tid']);
99  ?>
100  <tr>
101  <td style="font-weight: bold;"><?php echo $poll['poll_question']; ?></td>
102  <td><?php echo get_asset_tag_line($asset->_ipbid.':'.'o_'.$poll['pid']); ?></td>
103  <td><?php echo $data['poll_state']; ?></td>
104  </tr>
105  <?php
106  }
107  echo '</table>';
108  $o->closeField();
109  $o->closeSection();
110  }
111 
112  } else {
113 
114  $o->openSection('Details');
115  $poll_question = $asset->attr('poll_question');
116  $start_date = date('g:i:s D j M Y', $asset->attr('start_date'));
117 
118  $started_by = get_asset_tag_line($asset->_ipbid.':'.'u_'.$asset->attr('starter_id'));
119  $forum_tag_line = get_asset_tag_line($asset->_ipbid.':'.'f_'.$asset->attr('forum_id'));
120  $total_votes = $asset->attr('votes');
121  $fields = Array(
122  translate('poll_question') => $poll_question,
123  translate('start_date') => $start_date,
124  translate('started_by') => $started_by,
125  translate('forum') => $forum_tag_line,
126  translate('total_votes') => $total_votes,
127  );
128  foreach ($fields as $key => $value) {
129  $o->openField($key);
130  echo $value;
131  $o->closeField();
132  }
133 
134  $o->openField('Results');
135  $poll_data = @unserialize(stripslashes($asset->attr('choices')));
136  if ($poll_data === FALSE) {
137  echo '<b>'.translate('poll_result_error').'</b>';
138  } else {
139  $total_votes = $asset->attr('votes');
140  ?>
141  <table class="sq-backend-table">
142  <tr>
143  <th style="width: 40%"><?php echo translate('option'); ?></th>
144  <th style="width: 30%"><?php echo translate('votes'); ?></th>
145  <th style="width: 30%"><?php echo translate('percentage'); ?></th>
146  </tr>
147  <?php
148  foreach ($poll_data as $data) {
149  ?>
150  <tr>
151  <td><?php echo $data[1]; ?></td>
152  <td><?php echo $data[2]; ?></td>
153  <td><?php echo ($data[2]==0) ? 0 : ($data[2]/$total_votes) * 100; ?> %</td>
154  </tr>
155  <?php
156  }
157  echo '</table>';
158  }
159 
160  $o->closeField();
161 
162  $o->closeSection();
163  }//end else
164 
165  return FALSE;
166 
167  }//end paintPoll()
168 
169 
182  function processPoll(&$asset, &$o, $prefix)
183  {
184  return FALSE;
185 
186  }//end processPoll()
187 
188 
189 }//end class
190 
191 ?>