function polls_delete_choices($poll) { $choices = polls_get_choices($poll); if ($choices) { foreach ($choices as $choice) { $choice->delete(); } } }
<?php // TODO: add ability to reorder poll questions? $poll = $vars['poll']; $body = ''; $i = 0; if ($poll) { $choices = polls_get_choices($poll); if ($choices) { foreach ($choices as $choice) { $body .= '<div id="choice_container_' . $i . '">'; $body .= elgg_view('input/text', array('name' => 'choice_text_' . $i, 'value' => $choice->text, 'class' => 'input-poll-choice')); $body .= '<a href="#" alt="' . elgg_echo('polls:delete_choice') . '" title="' . elgg_echo('polls:delete_choice') . ' id="choice_delete_' . $i . '" onclick="javascript:polls_delete_choice(' . $i . '); return false;">'; $body .= '<img src="' . $vars['url'] . 'mod/polls/graphics/16-em-cross.png"></a>'; $body .= '</div>'; $i += 1; } } } $body .= elgg_view('input/hidden', array('name' => 'number_of_choices', 'id' => 'number_of_choices', 'value' => $i)); $body .= '<div id="new_choices_area"></div>'; $body .= elgg_view('input/button', array('id' => 'add_choice', 'value' => elgg_echo('polls:add_choice'), 'type' => 'button')); echo $body; ?> <script type="text/javascript"> $('#add_choice').click( function() { var cnum = parseInt($('#number_of_choices').val()); $('#number_of_choices').val(cnum+1); var new_html = '<div id="choice_container_'+cnum+'">'; new_html += '<input type="text" class="input-poll-choice" name="choice_text_'+cnum+'"> ';