$question ) { if ( ! empty( $question['VOTES'] ) ) { $voted_array[$question['ID']] = explode( '||', $question['VOTES'] ); if ( is_array( $votes_array[$question['ID']] ) ) // Multiple. { foreach ( (array) $votes_array[$question['ID']] as $checked_box ) { $voted_array[$question['ID']][$checked_box]++; } } else // Multiple_radio. { $voted_array[$question['ID']][$votes_array[$question['ID']]]++; } } else // First vote. { $voted_array[$question['ID']] = array(); $options_array = explode( "\r", str_replace( array( "\r\n", "\n" ), "\r", $question['OPTIONS'] ) ); if ( is_array( $votes_array[$question['ID']] ) ) // Multiple. { foreach ( (array) $options_array as $option_nb => $option_label ) { $voted_array[$question['ID']][$option_nb] = 0; } foreach ( (array) $votes_array[$question['ID']] as $checked_box ) { $voted_array[$question['ID']][$checked_box]++; } } else // Multiple_radio. { foreach ( (array) $options_array as $option_nb => $option_label ) { $voted_array[$question['ID']][$option_nb] = ( $votes_array[$question['ID']] == $option_nb ? 1 : 0 ); } } } $voted_array[$question['ID']] = implode( '||', $voted_array[$question['ID']] ); // Submit query. DBQuery( "UPDATE PORTAL_POLL_QUESTIONS SET VOTES='" . $voted_array[$question['ID']] . "' WHERE ID='" . $question['ID'] . "'" ); // Update the $poll_questions_RET array with Votes. $poll_questions_RET[$key]['VOTES'] = $voted_array[$question['ID']]; } return $poll_questions_RET; } /** * @param $value * @param $name */ function PortalPollsDisplay( $value, $name ) { global $THIS_RET; $poll_id = $THIS_RET['ID']; // Get poll: $poll_RET = DBGet( "SELECT EXCLUDED_USERS,VOTES_NUMBER,DISPLAY_VOTES FROM PORTAL_POLLS WHERE ID='" . $poll_id . "'" ); require_once 'ProgramFunctions/Linkify.fnc.php'; $poll_questions_RET = DBGet( "SELECT ID,QUESTION,OPTIONS,TYPE,VOTES FROM PORTAL_POLL_QUESTIONS WHERE PORTAL_POLL_ID='" . $poll_id . "' ORDER BY ID", array( 'OPTIONS' => 'Linkify' ) ); if ( ! $poll_RET || ! $poll_questions_RET ) { // Should never be displayed, so do not translate. return ErrorMessage( array( 'Poll does not exist' ) ); } $excluded_user = GetPortalPollUser(); if ( ! $excluded_user ) { // Should never be displayed, so do not translate. return ErrorMessage( array( 'User not logged in' ) ); } // Check if user is in excluded users list (format = '|[profile_id]:[user_id]'). if ( mb_strpos( $poll_RET[1]['EXCLUDED_USERS'] . '|', $excluded_user . '|' ) !== false ) { // User already voted, display votes. return PortalPollsVotesDisplay( $poll_id, $poll_RET[1]['DISPLAY_VOTES'], $poll_questions_RET, $poll_RET[1]['VOTES_NUMBER'] ); } return PortalPollForm( $poll_id, $poll_questions_RET ); } /** * Get poll user, using the excluded users format: * |[profile_id]:[user_id] * * @since 3.4 * * @return string User, empty if no user ID. */ function GetPortalPollUser() { $profile_id = User( 'PROFILE_ID' ); if ( $profile_id !== '0' ) // FJ call right Student/Staff ID. { $user_id = $_SESSION['STAFF_ID']; } else { $user_id = $_SESSION['STUDENT_ID']; } if ( ! $user_id ) { return ''; } return '|' . $profile_id . ':' . $user_id; } /** * Function called by PortalPollsDisplay() * generates the Portal Poll's HTML form * * @param integer $poll_id Poll ID. * @param array $poll_questions_RET Poll questions. * @return string Poll HTML form. */ function PortalPollForm( $poll_id, $poll_questions_RET ) { $poll_form = ''; //FJ responsive rt td too large if ( ! isset( $_REQUEST['_ROSARIO_PDF'] ) ) { $poll_form .= '
'; } $poll_form .= '
'; foreach ( (array) $poll_questions_RET as $question ) { $poll_form .= ''; } $poll_form .= '
' . $question['QUESTION'] . ' '; $options_array = explode( "\r", str_replace( array( "\r\n", "\n" ), "\r", $question['OPTIONS'] ) ); $checked = true; foreach ( $options_array as $option_nb => $option_label ) { if ( $question['TYPE'] == 'multiple_radio' ) { $poll_form .= '' . "\n"; } else // Multiple. { $poll_form .= '' . "\n"; } $checked = false; } $poll_form .= '

' . Buttons( _( 'Submit' ) ) . '

'; if ( ! isset( $_REQUEST['_ROSARIO_PDF'] ) ) { $poll_form .= '
'; } return $poll_form; } /** * @param $poll_id * @param $display_votes * @param $poll_questions_RET * @param $votes_number * @param $js_included_is_voting * @return mixed */ function PortalPollsVotesDisplay( $poll_id, $display_votes, $poll_questions_RET, $votes_number, $js_included_is_voting = false ) { if ( ! $display_votes ) { $note = button( 'check' ) . ' ' . _( 'Poll completed' ); return $note; } $votes_display = ''; // FJ responsive rt td too large. if ( ! $js_included_is_voting ) { $votes_display .= '
' . "\n"; } foreach ( (array) $poll_questions_RET as $question ) { $total_votes = 0; // Question. $votes_display .= '

' . $question['QUESTION'] . '

' . "\n"; // Votes. $votes_array = explode( '||', $question['VOTES'] ); foreach ( (array) $votes_array as $votes ) { $total_votes += $votes; } // Options. $options_array = explode( "\r", str_replace( array( "\r\n", "\n" ), "\r", $question['OPTIONS'] ) ); $options_array_count = count( $options_array ); for ( $i = 0; $i < $options_array_count; $i++ ) { $percent = round( ( $votes_array[$i] / $total_votes ) * 100 ); $votes_display .= '' . "\n"; } $votes_display .= '
' . $options_array[$i] . '
' . $percent . '
' . $percent . '%
' . "\n"; } $votes_display .= '

' . _( 'Total Participants' ) . ': ' . $votes_number . '

'; if ( ! $js_included_is_voting ) { $votes_display .= '
'; } return $votes_display; } // AJAX vote call: if ( isset( $_POST['votes'] ) && is_array( $_POST['votes'] ) ) { if ( empty( $_SERVER['HTTP_X_REQUESTED_WITH'] ) || $_SERVER['HTTP_X_REQUESTED_WITH'] !== 'XMLHttpRequest' ) { die( 'Error: no AJAX' ); } chdir( '../' ); require_once 'Warehouse.php'; foreach ( (array) $_POST['votes'] as $poll_id => $votes_array ) { if ( ! empty( $votes_array ) ) { echo PortalPollsVote( $poll_id, $votes_array ); break; } } exit(); } /** * @param $value * @param $name * @return mixed */ function makePublishing( $value, $name ) { global $THIS_RET; static $profiles = null; if ( ! empty( $THIS_RET['ID'] ) ) { $id = $THIS_RET['ID']; } else { $id = 'new'; } //FJ responsive rt td too large $return = '
' . "\n"; //FJ remove LO_field $return .= ''; $return .= '
' . _( 'Visible Between' ) . ':
'; $return .= DateInput( $value, 'values[' . $id . '][' . $name . ']' ) . ' ' . _( 'to' ) . ' '; $return .= DateInput( issetVal( $THIS_RET['END_DATE'] ), 'values[' . $id . '][END_DATE]' ) . '
'; if ( is_null( $profiles ) ) { $profiles_RET = DBGet( "SELECT ID,TITLE FROM USER_PROFILES ORDER BY ID" ); //add Profiles with Custom permissions to profiles list $profiles = array_merge( array( array( 'ID' => 'admin', 'TITLE' => _( 'Administrator w/Custom' ) ), array( 'ID' => 'teacher', 'TITLE' => _( 'Teacher w/Custom' ) ), array( 'ID' => 'parent', 'TITLE' => _( 'Parent w/Custom' ) ), ), $profiles_RET ); } $return .= makePublishingVisibleTo( $profiles, $THIS_RET, $id ); $return .= '
'; if ( ! isset( $_REQUEST['_ROSARIO_PDF'] ) ) { $return .= '
'; } return $return; } /** * Function called by makePublishing() * generates the "Visible To" part of the Publishing options * * @todo Use a Multiple select input to gain space. * * @return $visibleTo HTML form */ function makePublishingVisibleTo( $profiles, $THIS_RET, $id ) { $visibleTo = ''; // FJ Portal Polls add students teacher. $teachers_RET = DBGet( "SELECT STAFF_ID," . DisplayNameSQL() . " AS FULL_NAME FROM STAFF WHERE (SCHOOLS IS NULL OR STRPOS(SCHOOLS,'," . UserSchool() . ",')>0) AND SYEAR='" . UserSyear() . "' AND PROFILE='teacher' ORDER BY LAST_NAME,FIRST_NAME" ); $teachers = array(); foreach ( (array) $teachers_RET as $teacher ) { $teachers[$teacher['STAFF_ID']] = $teacher['FULL_NAME']; } $i = 0; foreach ( (array) $profiles as $profile ) { $i++; $checked = mb_strpos( issetVal( $THIS_RET['PUBLISHED_PROFILES'] ), ',' . $profile['ID'] . ',' ) !== false; $visibleTo .= ''; if ( $i % 2 == 0 && $i != count( $profiles ) ) { $visibleTo .= ''; } } for ( ; $i % 2 != 0; $i++ ) { $visibleTo .= ''; } $visibleTo .= ''; if ( $_REQUEST['modname'] == 'School_Setup/PortalNotes.php' ) { //hook $args = $id; do_action( 'School_Setup/PortalNotes.php|portal_note_field', $args ); } $visibleTo .= '
' . _( 'Visible To' ) . ':
' . CheckboxInput( $checked, 'profiles[' . $id . '][' . $profile['ID'] . ']', _( $profile['TITLE'] ), '', true ); //FJ Portal Polls add students teacher if ( $profile['ID'] === '0' && $_REQUEST['modname'] == 'School_Setup/PortalPolls.php' ) //student & verify this is not a Portal Note! { $visibleTo .= ': ' . SelectInput( issetVal( $THIS_RET['STUDENTS_TEACHER_ID'] ), 'values[' . $id . '][STUDENTS_TEACHER_ID]', _( 'Limit to Teacher' ), $teachers, 'N/A', '', true ); } $visibleTo .= '
 
'; return $visibleTo; } //FJ file attached to portal notes /** * @param $value * @param $name * @return mixed */ function makeFileAttached( $value, $name ) { global $THIS_RET, $PortalNotesFilesPath; static $filesAttachedCount = 0; if ( ! empty( $THIS_RET['ID'] ) ) { $id = $THIS_RET['ID']; if ( empty( $value ) ) { return ' '; } $filesAttachedCount++; //FJ colorbox $view_online = ' ' . _( 'View Online' ) . ''; $download = ' ' . _( 'Download' ) . ''; if ( filter_var( $value, FILTER_VALIDATE_URL ) !== false ) //embed link { return '' . $view_online . ''; } return '' . $download . ''; } $id = 'new'; $return = '
'; $return .= FileInput( $name . '_FILE', _( 'File Attached' ) ); $return .= '
' . TextInput( '', 'values[' . $id . '][' . $name . '_EMBED]', _( 'Embed Link' ), 'size="14" placeholder="http://"' ) . '
'; return $return; }