Beispiel #1
0
function ciniki_conferences_conferenceGet($ciniki)
{
    //
    // Find all the required and optional arguments
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'prepareArgs');
    $rc = ciniki_core_prepareArgs($ciniki, 'no', array('business_id' => array('required' => 'yes', 'blank' => 'no', 'name' => 'Business'), 'conference_id' => array('required' => 'yes', 'blank' => 'no', 'name' => 'Conference'), 'cfplogs' => array('required' => 'no', 'blank' => 'yes', 'name' => 'CFP Log Entries'), 'presentations' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Presentations'), 'presentation_status' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Presentations'), 'registration_status' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Registrations'), 'presentation_type' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Presentations'), 'reviewers' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Reviewers'), 'attendees' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Attendees'), 'attendee_status' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Presentations'), 'rooms' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Rooms'), 'sessions' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Session'), 'sessionpresentations' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Assigned Presentations'), 'stats' => array('required' => 'no', 'blank' => 'yes', 'name' => 'Stats')));
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    $args = $rc['args'];
    //
    // Make sure this module is activated, and
    // check permission to run this function for this business
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'conferences', 'private', 'checkAccess');
    $rc = ciniki_conferences_checkAccess($ciniki, $args['business_id'], 'ciniki.conferences.conferenceGet');
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbHashQuery');
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbHashQueryArrayTree');
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbHashQueryIDTree');
    //
    // Load business settings
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'businesses', 'private', 'intlSettings');
    $rc = ciniki_businesses_intlSettings($ciniki, $args['business_id']);
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    $intl_timezone = $rc['settings']['intl-default-timezone'];
    $intl_currency_fmt = numfmt_create($rc['settings']['intl-default-locale'], NumberFormatter::CURRENCY);
    $intl_currency = $rc['settings']['intl-default-currency'];
    ciniki_core_loadMethod($ciniki, 'ciniki', 'users', 'private', 'dateFormat');
    ciniki_core_loadMethod($ciniki, 'ciniki', 'users', 'private', 'timeFormat');
    $date_format = ciniki_users_dateFormat($ciniki, 'php');
    $time_format = ciniki_users_timeFormat($ciniki, 'php');
    $mysql_date_format = ciniki_users_dateFormat($ciniki, 'mysql');
    //
    // Load conference maps
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'conferences', 'private', 'maps');
    $rc = ciniki_conferences_maps($ciniki);
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    $maps = $rc['maps'];
    //
    // Return default for new Conference
    //
    $email_list = '';
    if ($args['conference_id'] == 0) {
        $conference = array('id' => 0, 'name' => '', 'permalink' => '', 'status' => '10', 'flags' => '0', 'start_date' => '', 'end_date' => '', 'synopsis' => '', 'description' => '');
    } else {
        $strsql = "SELECT ciniki_conferences.id, " . "ciniki_conferences.name, " . "ciniki_conferences.permalink, " . "ciniki_conferences.status, " . "ciniki_conferences.status AS status_text, " . "ciniki_conferences.flags, " . "DATE_FORMAT(ciniki_conferences.start_date, '" . ciniki_core_dbQuote($ciniki, $mysql_date_format) . "') AS start_date, " . "DATE_FORMAT(ciniki_conferences.end_date, '" . ciniki_core_dbQuote($ciniki, $mysql_date_format) . "') AS end_date, " . "ciniki_conferences.synopsis, " . "ciniki_conferences.description, " . "ciniki_conferences.imap_mailbox, " . "ciniki_conferences.imap_username, " . "ciniki_conferences.imap_password, " . "ciniki_conferences.imap_subject " . "FROM ciniki_conferences " . "WHERE ciniki_conferences.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND ciniki_conferences.id = '" . ciniki_core_dbQuote($ciniki, $args['conference_id']) . "' " . "";
        $rc = ciniki_core_dbHashQuery($ciniki, $strsql, 'ciniki.conferences', 'conference');
        if ($rc['stat'] != 'ok') {
            return array('stat' => 'fail', 'err' => array('pkg' => 'ciniki', 'code' => '2840', 'msg' => 'Conference not found', 'err' => $rc['err']));
        }
        if (!isset($rc['conference'])) {
            return array('stat' => 'fail', 'err' => array('pkg' => 'ciniki', 'code' => '2841', 'msg' => 'Unable to find Conference'));
        }
        $conference = $rc['conference'];
        if (isset($maps['conference']['status'][$conference['status_text']])) {
            $conference['status_text'] = $maps['conference']['status'][$conference['status_text']];
        }
        //
        // Check if CFP logs should be returned
        //
        if (isset($args['cfplogs']) && $args['cfplogs'] == 'yes') {
            $strsql = "SELECT ciniki_conferences_cfplogs.id, " . "ciniki_conferences_cfplogs.name, " . "ciniki_conferences_cfplogs.url, " . "ciniki_conferences_cfplogs.sent_date, " . "ciniki_conferences_cfplogs.email " . "FROM ciniki_conferences_cfplogs " . "WHERE ciniki_conferences_cfplogs.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND ciniki_conferences_cfplogs.conference_id = '" . ciniki_core_dbQuote($ciniki, $args['conference_id']) . "' " . "";
            $rc = ciniki_core_dbHashQueryArrayTree($ciniki, $strsql, 'ciniki.conferences', array(array('container' => 'cfplogs', 'fname' => 'id', 'fields' => array('id', 'name', 'url', 'email', 'sent_date'), 'utctotz' => array('sent_date' => array('format' => $date_format, 'timezone' => 'UTC')))));
            if ($rc['stat'] != 'ok') {
                return $rc;
            }
            if (isset($rc['cfplogs'])) {
                $conference['cfplogs'] = $rc['cfplogs'];
            } else {
                $conference['cfplogs'] = array();
            }
        }
        //
        // Check if presentations should be returned
        //
        if (isset($args['presentations']) && $args['presentations'] == 'yes') {
            $strsql = "SELECT ciniki_conferences_presentations.id, " . "ciniki_conferences_presentations.conference_id, " . "ciniki_conferences_presentations.customer_id, " . "ciniki_customers.display_name, " . "ciniki_conferences_presentations.presentation_number, " . "ciniki_conferences_presentations.presentation_type, " . "ciniki_conferences_presentations.presentation_type AS presentation_type_text, " . "ciniki_conferences_presentations.status, " . "ciniki_conferences_presentations.status AS status_text, " . "IFNULL(ciniki_conferences_attendees.status, 0) AS registration, " . "IFNULL(ciniki_conferences_attendees.status, 0) AS registration_text, " . "ciniki_conferences_presentations.submission_date, " . "ciniki_conferences_presentations.field, " . "ciniki_conferences_presentations.title, " . "ciniki_conferences_presentations.permalink, " . "IF(ciniki_conferences_presentation_reviews.vote > 0, 'yes', 'no') AS voted, " . "COUNT(ciniki_conferences_presentation_reviews.id) AS num_votes " . "FROM ciniki_conferences_presentations " . "LEFT JOIN ciniki_conferences_attendees ON (" . "ciniki_conferences_presentations.customer_id = ciniki_conferences_attendees.customer_id " . "AND ciniki_conferences_presentations.conference_id = ciniki_conferences_attendees.conference_id " . "AND ciniki_conferences_attendees.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . ") " . "LEFT JOIN ciniki_customers ON (" . "ciniki_conferences_presentations.customer_id = ciniki_customers.id " . "AND ciniki_customers.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . ") " . "LEFT JOIN ciniki_conferences_presentation_reviews ON (" . "ciniki_conferences_presentations.id = ciniki_conferences_presentation_reviews.presentation_id " . "AND ciniki_conferences_presentation_reviews.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . ") " . "WHERE ciniki_conferences_presentations.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "";
            if (isset($args['presentation_status']) && $args['presentation_status'] > 0) {
                $strsql .= "AND ciniki_conferences_presentations.status = '" . ciniki_core_dbQuote($ciniki, $args['presentation_status']) . "' ";
            }
            if (isset($args['presentation_type']) && $args['presentation_type'] > 0) {
                $strsql .= "AND ciniki_conferences_presentations.presentation_type = '" . ciniki_core_dbQuote($ciniki, $args['presentation_type']) . "' ";
            }
            $strsql .= "GROUP BY ciniki_conferences_presentations.id, voted ";
            if (isset($args['registration_status']) && $args['registration_status'] != '') {
                $strsql .= "HAVING registration = '" . ciniki_core_dbQuote($ciniki, $args['registration_status']) . "' ";
            }
            $strsql .= "ORDER BY submission_date ";
            $rc = ciniki_core_dbHashQueryArrayTree($ciniki, $strsql, 'ciniki.conferences', array(array('container' => 'presentations', 'fname' => 'id', 'fields' => array('id', 'conference_id', 'customer_id', 'presentation_type', 'presentation_number', 'status', 'status_text', 'registration', 'registration_text', 'submission_date', 'field', 'title', 'display_name', 'permalink'), 'utctotz' => array('submission_date' => array('format' => 'M j', 'timezone' => $intl_timezone)), 'maps' => array('status_text' => $maps['presentation']['status'], 'registration_text' => $maps['attendee']['status'], 'presentation_type_text' => $maps['presentation']['presentation_type'])), array('container' => 'voted', 'fname' => 'voted', 'fields' => array('voted', 'num_votes'))));
            if ($rc['stat'] != 'ok') {
                return $rc;
            }
            $customer_ids = array();
            if (isset($rc['presentations'])) {
                $conference['presentations'] = $rc['presentations'];
                foreach ($conference['presentations'] as $pid => $presentation) {
                    $customer_ids[] = $presentation['customer_id'];
                    $conference['presentations'][$pid]['display_title'] = sprintf("#%03d: ", $presentation['presentation_number']) . $presentation['title'];
                    $conference['presentations'][$pid]['votes_received'] = 0;
                    $conference['presentations'][$pid]['total_reviews'] = 0;
                    if (isset($presentation['voted'])) {
                        foreach ($presentation['voted'] as $vote) {
                            $conference['presentations'][$pid]['total_reviews'] += $vote['num_votes'];
                            if ($vote['voted'] == 'yes') {
                                $conference['presentations'][$pid]['votes_received'] += $vote['num_votes'];
                            }
                        }
                        unset($conference['presentations'][$pid]['voted']);
                    }
                }
            } else {
                $conference['presentations'] = array();
            }
            //
            // Get the email list
            //
            if (isset($customer_ids) && count($customer_ids) > 0) {
                ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbQuoteIDs');
                $strsql = "SELECT ciniki_customers.display_name, " . "ciniki_customer_emails.email " . "FROM ciniki_customers " . "LEFT JOIN ciniki_customer_emails ON (" . "ciniki_customers.id = ciniki_customer_emails.customer_id " . "AND ciniki_customer_emails.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . ") " . "WHERE ciniki_customers.id IN (" . ciniki_core_dbQuoteIDs($ciniki, $customer_ids) . ") " . "AND ciniki_customers.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "";
                $rc = ciniki_core_dbHashQueryArrayTree($ciniki, $strsql, 'ciniki.conferences', array(array('container' => 'emails', 'fname' => 'email', 'fields' => array('display_name', 'email'))));
                if ($rc['stat'] != 'ok') {
                    return $rc;
                }
                if (isset($rc['emails'])) {
                    foreach ($rc['emails'] as $email) {
                        $email_list .= ($email_list != '' ? ",\n" : '') . '"' . $email['display_name'] . '" <' . $email['email'] . '>';
                    }
                }
            }
        }
        //
        // Get the reviewers for the conference
        //
        if (isset($args['reviewers']) && $args['reviewers'] == 'yes') {
            $strsql = "SELECT ciniki_conferences_presentation_reviews.id, " . "ciniki_conferences_presentation_reviews.customer_id, " . "ciniki_customers.display_name, " . "IF(ciniki_conferences_presentation_reviews.vote > 0, 'yes', 'no') AS voted, " . "COUNT(ciniki_conferences_presentation_reviews.id) AS num_votes " . "FROM ciniki_conferences_presentation_reviews " . "LEFT JOIN ciniki_customers ON (" . "ciniki_conferences_presentation_reviews.customer_id = ciniki_customers.id " . "AND ciniki_customers.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . ") " . "WHERE ciniki_conferences_presentation_reviews.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND ciniki_conferences_presentation_reviews.conference_id = '" . ciniki_core_dbQuote($ciniki, $args['conference_id']) . "' " . "GROUP BY ciniki_conferences_presentation_reviews.customer_id, voted " . "";
            $rc = ciniki_core_dbHashQueryArrayTree($ciniki, $strsql, 'ciniki.conferences', array(array('container' => 'reviewers', 'fname' => 'customer_id', 'fields' => array('id', 'customer_id', 'display_name')), array('container' => 'voted', 'fname' => 'voted', 'fields' => array('voted', 'num_votes'))));
            if ($rc['stat'] != 'ok') {
                return $rc;
            }
            if (isset($rc['reviewers'])) {
                $conference['reviewers'] = $rc['reviewers'];
                foreach ($conference['reviewers'] as $rid => $review) {
                    $conference['reviewers'][$rid]['votes_received'] = 0;
                    $conference['reviewers'][$rid]['total_reviews'] = 0;
                    if (isset($review['voted'])) {
                        foreach ($review['voted'] as $vote) {
                            $conference['reviewers'][$rid]['total_reviews'] += $vote['num_votes'];
                            if ($vote['voted'] == 'yes') {
                                $conference['reviewers'][$rid]['votes_received'] += $vote['num_votes'];
                            }
                        }
                        unset($conference['reviewers'][$rid]['voted']);
                    }
                }
            } else {
                $conference['reviewers'] = array();
            }
        }
        //
        // Get the attendees for the conference
        //
        if (isset($args['attendees']) && $args['attendees'] == 'yes') {
            $strsql = "SELECT ciniki_conferences_attendees.id, " . "ciniki_conferences_attendees.customer_id, " . "ciniki_customers.display_name, " . "ciniki_customers.sort_name, " . "ciniki_customers.company, " . "ciniki_conferences_attendees.status, " . "ciniki_conferences_attendees.status AS status_text, " . "IFNULL(ciniki_customer_emails.email, '') AS emails, " . "IF(IFNULL(ciniki_conferences_presentations.id, 0) > 0, 'Yes', 'No') AS presenter " . "FROM ciniki_conferences_attendees " . "LEFT JOIN ciniki_conferences_presentations ON (" . "ciniki_conferences_attendees.customer_id = ciniki_conferences_presentations.customer_id " . "AND ciniki_conferences_attendees.conference_id = ciniki_conferences_presentations.conference_id " . "AND ciniki_conferences_presentations.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . ") " . "LEFT JOIN ciniki_customers ON (" . "ciniki_conferences_attendees.customer_id = ciniki_customers.id " . "AND ciniki_customers.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . ") " . "LEFT JOIN ciniki_customer_emails ON (" . "ciniki_customers.id = ciniki_customer_emails.customer_id " . "AND ciniki_customer_emails.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . ") " . "WHERE ciniki_conferences_attendees.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND ciniki_conferences_attendees.conference_id = '" . ciniki_core_dbQuote($ciniki, $args['conference_id']) . "' " . "";
            if (isset($args['attendee_status']) && $args['attendee_status'] != '') {
                $strsql .= "AND ciniki_conferences_attendees.status = '" . ciniki_core_dbQuote($ciniki, $args['attendee_status']) . "' ";
            }
            $strsql .= "GROUP BY ciniki_customers.display_name, ciniki_customers.id ";
            $strsql .= "ORDER BY ciniki_customers.sort_name ";
            $rc = ciniki_core_dbHashQueryArrayTree($ciniki, $strsql, 'ciniki.conferences', array(array('container' => 'attendees', 'fname' => 'id', 'fields' => array('id', 'customer_id', 'display_name', 'sort_name', 'company', 'status', 'status_text', 'emails', 'presenter'), 'lists' => array('emails' => ','), 'maps' => array('status_text' => $maps['attendee']['status']))));
            if ($rc['stat'] != 'ok') {
                return $rc;
            }
            if (isset($rc['attendees'])) {
                $conference['attendees'] = $rc['attendees'];
                foreach ($conference['attendees'] as $attendee) {
                    $email_list .= ($email_list != '' ? ", \n" : '') . '"' . $attendee['display_name'] . '" <' . $attendee['emails'] . '>';
                }
            } else {
                $conference['attendees'] = array();
                $email_list = '';
            }
        }
        //
        // Get the presentations ordered by sessions, and then unassigned presentations
        //
        if (isset($args['sessionpresentations']) && $args['sessionpresentations'] == 'yes') {
            $strsql = "SELECT ciniki_conferences_sessions.id, " . "CONCAT_WS('-', ciniki_conferences_sessions.id, ciniki_conferences_presentations.id) AS rowid, " . "ciniki_conferences_sessions.conference_id, " . "ciniki_conferences_sessions.room_id, " . "ciniki_conferences_rooms.name AS room, " . "ciniki_conferences_rooms.sequence, " . "ciniki_conferences_sessions.name, " . "ciniki_conferences_sessions.session_start AS start_time, " . "ciniki_conferences_sessions.session_start AS start_date, " . "ciniki_conferences_sessions.session_end AS end_time, " . "IFNULL(ciniki_conferences_presentations.id, 0) AS presentation_id, " . "IFNULL(ciniki_conferences_presentations.customer_id, 0) AS customer_id, " . "IFNULL(ciniki_conferences_presentations.presentation_number, '') AS presentation_number, " . "IFNULL(ciniki_conferences_presentations.title, '') AS presentation_title, " . "IFNULL(ciniki_customers.display_name, '') AS display_name, " . "IFNULL(ciniki_conferences_presentations.status, 0) AS status, " . "IFNULL(ciniki_conferences_presentations.status, '') AS status_text, " . "IFNULL(ciniki_conferences_attendees.status, 0) AS registration, " . "IFNULL(ciniki_conferences_attendees.status, 0) AS registration_text " . "FROM ciniki_conferences_sessions " . "INNER JOIN ciniki_conferences_rooms ON (" . "ciniki_conferences_sessions.room_id = ciniki_conferences_rooms.id " . "AND ciniki_conferences_rooms.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . ") " . "LEFT JOIN ciniki_conferences_presentations ON (" . "ciniki_conferences_sessions.id = ciniki_conferences_presentations.session_id " . "AND ciniki_conferences_presentations.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . ") " . "LEFT JOIN ciniki_conferences_attendees ON (" . "ciniki_conferences_presentations.customer_id = ciniki_conferences_attendees.customer_id " . "AND ciniki_conferences_presentations.conference_id = ciniki_conferences_attendees.conference_id " . "AND ciniki_conferences_attendees.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . ") " . "LEFT JOIN ciniki_customers ON (" . "ciniki_conferences_presentations.customer_id = ciniki_customers.id " . "AND ciniki_customers.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . ") " . "WHERE ciniki_conferences_sessions.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND ciniki_conferences_sessions.conference_id = '" . ciniki_core_dbQuote($ciniki, $args['conference_id']) . "' " . "ORDER BY ciniki_conferences_sessions.session_start, " . "ciniki_conferences_rooms.sequence, " . "ciniki_conferences_rooms.name, " . "ciniki_conferences_presentations.title " . "";
            ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbHashQueryArrayTree');
            $rc = ciniki_core_dbHashQueryArrayTree($ciniki, $strsql, 'ciniki.conferences', array(array('container' => 'sessions', 'fname' => 'rowid', 'fields' => array('id', 'conference_id', 'room_id', 'room', 'sequence', 'name', 'start_time', 'start_date', 'end_time', 'presentation_id', 'customer_id', 'presentation_number', 'presentation_title', 'display_name', 'status', 'status_text', 'registration', 'registration_text'), 'utctotz' => array('start_time' => array('format' => $time_format, 'timezone' => $intl_timezone), 'start_date' => array('format' => $date_format, 'timezone' => $intl_timezone), 'end_time' => array('format' => $time_format, 'timezone' => $intl_timezone)), 'maps' => array('status_text' => $maps['presentation']['status'], 'registration_text' => $maps['attendee']['status']))));
            if ($rc['stat'] != 'ok') {
                return $rc;
            }
            if (isset($rc['sessions'])) {
                $conference['assignedpresentations'] = $rc['sessions'];
                foreach ($conference['assignedpresentations'] as $pid => $presentation) {
                    if ($presentation['presentation_id'] > 0) {
                        $conference['assignedpresentations'][$pid]['display_title'] = sprintf("#%03d: ", $presentation['presentation_number']) . $presentation['presentation_title'];
                    } else {
                        $conference['assignedpresentations'][$pid]['display_title'] = '';
                    }
                }
            } else {
                $conference['assignedpresentations'] = array();
            }
            //
            // Get the list of unassigned presentations
            //
            $strsql = "SELECT ciniki_conferences_presentations.id, " . "ciniki_conferences_presentations.conference_id, " . "ciniki_conferences_presentations.customer_id, " . "ciniki_customers.display_name, " . "ciniki_conferences_presentations.presentation_number, " . "ciniki_conferences_presentations.presentation_type, " . "ciniki_conferences_presentations.presentation_type AS presentation_type_text, " . "ciniki_conferences_presentations.status, " . "ciniki_conferences_presentations.status AS status_text, " . "IFNULL(ciniki_conferences_attendees.status, 0) AS registration, " . "IFNULL(ciniki_conferences_attendees.status, 0) AS registration_text, " . "ciniki_conferences_presentations.submission_date, " . "ciniki_conferences_presentations.field, " . "ciniki_conferences_presentations.title, " . "ciniki_conferences_presentations.permalink " . "FROM ciniki_conferences_presentations " . "LEFT JOIN ciniki_conferences_attendees ON (" . "ciniki_conferences_presentations.customer_id = ciniki_conferences_attendees.customer_id " . "AND ciniki_conferences_presentations.conference_id = ciniki_conferences_attendees.conference_id " . "AND ciniki_conferences_attendees.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . ") " . "LEFT JOIN ciniki_customers ON (" . "ciniki_conferences_presentations.customer_id = ciniki_customers.id " . "AND ciniki_customers.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . ") " . "WHERE ciniki_conferences_presentations.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND ciniki_conferences_presentations.session_id = 0 " . "AND ciniki_conferences_presentations.status = 30 " . "HAVING registration = 30 " . "ORDER BY submission_date " . "";
            $rc = ciniki_core_dbHashQueryArrayTree($ciniki, $strsql, 'ciniki.conferences', array(array('container' => 'presentations', 'fname' => 'id', 'fields' => array('id', 'conference_id', 'customer_id', 'presentation_type', 'presentation_number', 'status', 'status_text', 'registration', 'registration_text', 'submission_date', 'field', 'title', 'display_name', 'permalink'), 'maps' => array('status_text' => $maps['presentation']['status'], 'registration_text' => $maps['attendee']['status'], 'presentation_type_text' => $maps['presentation']['presentation_type']))));
            if ($rc['stat'] != 'ok') {
                return $rc;
            }
            if (isset($rc['presentations'])) {
                $conference['unassignedpresentations'] = $rc['presentations'];
                foreach ($conference['unassignedpresentations'] as $pid => $presentation) {
                    $conference['unassignedpresentations'][$pid]['display_title'] = sprintf("#%03d: ", $presentation['presentation_number']) . $presentation['title'];
                }
            } else {
                $conference['unassignedpresentations'] = array();
            }
        }
        //
        // Get the list of sessions
        //
        if (isset($args['sessions']) && $args['sessions'] == 'yes') {
            $strsql = "SELECT ciniki_conferences_sessions.id, " . "ciniki_conferences_sessions.conference_id, " . "ciniki_conferences_sessions.room_id, " . "ciniki_conferences_sessions.name, " . "ciniki_conferences_rooms.name AS room, " . "ciniki_conferences_rooms.sequence, " . "ciniki_conferences_sessions.session_start AS start_time, " . "ciniki_conferences_sessions.session_start AS start_date, " . "ciniki_conferences_sessions.session_end AS end_time " . "FROM ciniki_conferences_sessions " . "INNER JOIN ciniki_conferences_rooms ON (" . "ciniki_conferences_sessions.room_id = ciniki_conferences_rooms.id " . "AND ciniki_conferences_rooms.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND ciniki_conferences_rooms.conference_id = '" . ciniki_core_dbQuote($ciniki, $args['conference_id']) . "' " . ") " . "WHERE ciniki_conferences_sessions.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND ciniki_conferences_sessions.conference_id = '" . ciniki_core_dbQuote($ciniki, $args['conference_id']) . "' " . "ORDER BY ciniki_conferences_sessions.session_start, ciniki_conferences_rooms.sequence, ciniki_conferences_rooms.name " . "";
            ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbHashQueryArrayTree');
            $rc = ciniki_core_dbHashQueryArrayTree($ciniki, $strsql, 'ciniki.conferences', array(array('container' => 'sessions', 'fname' => 'id', 'fields' => array('id', 'conference_id', 'name', 'room_id', 'room', 'sequence', 'start_time', 'start_date', 'end_time'), 'utctotz' => array('start_time' => array('format' => $time_format, 'timezone' => $intl_timezone), 'start_date' => array('format' => $date_format, 'timezone' => $intl_timezone), 'end_time' => array('format' => $time_format, 'timezone' => $intl_timezone)))));
            if ($rc['stat'] != 'ok') {
                return $rc;
            }
            if (isset($rc['sessions'])) {
                $conference['sessions'] = $rc['sessions'];
            } else {
                $conference['sessions'] = array();
            }
        }
        //
        // Get the list of rooms
        //
        if (isset($args['rooms']) && $args['rooms'] == 'yes') {
            $strsql = "SELECT ciniki_conferences_rooms.id, " . "ciniki_conferences_rooms.conference_id, " . "ciniki_conferences_rooms.name, " . "ciniki_conferences_rooms.sequence " . "FROM ciniki_conferences_rooms " . "WHERE ciniki_conferences_rooms.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND ciniki_conferences_rooms.conference_id = '" . ciniki_core_dbQuote($ciniki, $args['conference_id']) . "' " . "ORDER BY sequence, name " . "";
            ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbHashQueryArrayTree');
            $rc = ciniki_core_dbHashQueryArrayTree($ciniki, $strsql, 'ciniki.conferences', array(array('container' => 'rooms', 'fname' => 'id', 'fields' => array('id', 'conference_id', 'name', 'sequence'))));
            if ($rc['stat'] != 'ok') {
                return $rc;
            }
            if (isset($rc['rooms'])) {
                $conference['rooms'] = $rc['rooms'];
            } else {
                $conference['rooms'] = array();
            }
        }
        //
        // Get the stats for the conference
        //
        if (isset($args['stats']) && $args['stats'] == 'yes') {
            $strsql = "SELECT status, COUNT(status) AS num_presentations " . "FROM ciniki_conferences_presentations " . "WHERE ciniki_conferences_presentations.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND ciniki_conferences_presentations.conference_id = '" . ciniki_core_dbQuote($ciniki, $args['conference_id']) . "' " . "GROUP BY status " . "";
            $rc = ciniki_core_dbHashQueryIDTree($ciniki, $strsql, 'ciniki.conferences', array(array('container' => 'stats', 'fname' => 'status', 'fields' => array('status', 'num_presentations'))));
            if ($rc['stat'] != 'ok') {
                return $rc;
            }
            $conference['presentation_stats'] = array();
            foreach ($maps['presentation']['status'] as $status => $status_text) {
                $conference['presentation_stats'][$status] = array('name' => $status_text, 'count' => isset($rc['stats'][$status]['num_presentations']) ? $rc['stats'][$status]['num_presentations'] : 0);
            }
            //
            // Get the attendee stats
            //
            $strsql = "SELECT status, COUNT(status) AS num_attendees " . "FROM ciniki_conferences_attendees " . "WHERE ciniki_conferences_attendees.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND ciniki_conferences_attendees.conference_id = '" . ciniki_core_dbQuote($ciniki, $args['conference_id']) . "' " . "GROUP BY status " . "";
            $rc = ciniki_core_dbHashQueryIDTree($ciniki, $strsql, 'ciniki.conferences', array(array('container' => 'stats', 'fname' => 'status', 'fields' => array('status', 'num_attendees'))));
            if ($rc['stat'] != 'ok') {
                return $rc;
            }
            $conference['attendee_stats'] = array();
            foreach ($maps['attendee']['status'] as $status => $status_text) {
                $conference['attendee_stats'][$status] = array('name' => $status_text, 'count' => isset($rc['stats'][$status]['num_attendees']) ? $rc['stats'][$status]['num_attendees'] : 0);
            }
            //
            // Get the registration stats
            //
            $strsql = "SELECT IFNULL(ciniki_conferences_attendees.status, 0) AS status, COUNT(*) AS num_attendees " . "FROM ciniki_conferences_presentations " . "LEFT JOIN ciniki_conferences_attendees ON (" . "ciniki_conferences_presentations.customer_id = ciniki_conferences_attendees.customer_id " . "AND ciniki_conferences_attendees.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND ciniki_conferences_attendees.conference_id = '" . ciniki_core_dbQuote($ciniki, $args['conference_id']) . "' " . ") " . "WHERE ciniki_conferences_presentations.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND ciniki_conferences_presentations.conference_id = '" . ciniki_core_dbQuote($ciniki, $args['conference_id']) . "' " . "";
            if (isset($args['presentation_status']) && $args['presentation_status'] > 0) {
                $strsql .= "AND ciniki_conferences_presentations.status = '" . ciniki_core_dbQuote($ciniki, $args['presentation_status']) . "' ";
            }
            if (isset($args['presentation_type']) && $args['presentation_type'] > 0) {
                $strsql .= "AND ciniki_conferences_presentations.presentation_type = '" . ciniki_core_dbQuote($ciniki, $args['presentation_type']) . "' ";
            }
            $strsql .= "GROUP BY status " . "";
            $rc = ciniki_core_dbHashQueryIDTree($ciniki, $strsql, 'ciniki.conferences', array(array('container' => 'stats', 'fname' => 'status', 'fields' => array('status', 'num_attendees'))));
            if ($rc['stat'] != 'ok') {
                return $rc;
            }
            foreach ($maps['attendee']['status'] as $type => $type_text) {
                $conference['registration_statuses'][$type] = array('name' => $type_text, 'count' => isset($rc['stats'][$type]['num_attendees']) ? $rc['stats'][$type]['num_attendees'] : 0);
            }
            //
            // Get the types for the conference
            //
            $strsql = "SELECT presentation_type, COUNT(*) AS num_presentations " . "FROM ciniki_conferences_presentations " . "WHERE ciniki_conferences_presentations.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND ciniki_conferences_presentations.conference_id = '" . ciniki_core_dbQuote($ciniki, $args['conference_id']) . "' " . "GROUP BY presentation_type " . "";
            $rc = ciniki_core_dbHashQueryIDTree($ciniki, $strsql, 'ciniki.conferences', array(array('container' => 'stats', 'fname' => 'presentation_type', 'fields' => array('presentation_type', 'num_presentations'))));
            if ($rc['stat'] != 'ok') {
                return $rc;
            }
            $conference['presentation_types'] = array();
            foreach ($maps['presentation']['presentation_type'] as $type => $type_text) {
                $conference['presentation_types'][$type] = array('name' => $type_text, 'count' => isset($rc['stats'][$type]['num_presentations']) ? $rc['stats'][$type]['num_presentations'] : 0);
            }
        }
    }
    return array('stat' => 'ok', 'conference' => $conference, 'emails' => $email_list);
}
function ciniki_conferences_conferenceScheduleDownload($ciniki)
{
    //
    // Find all the required and optional arguments
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'prepareArgs');
    $rc = ciniki_core_prepareArgs($ciniki, 'no', array('business_id' => array('required' => 'yes', 'blank' => 'no', 'name' => 'Business'), 'conference_id' => array('required' => 'yes', 'blank' => 'no', 'name' => 'Conference')));
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    $args = $rc['args'];
    //
    // Make sure this module is activated, and
    // check permission to run this function for this business
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'conferences', 'private', 'checkAccess');
    $rc = ciniki_conferences_checkAccess($ciniki, $args['business_id'], 'ciniki.conferences.conferenceScheduleDownload');
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbHashQuery');
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbHashQueryArrayTree');
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbHashQueryIDTree');
    //
    // Load business settings
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'businesses', 'private', 'intlSettings');
    $rc = ciniki_businesses_intlSettings($ciniki, $args['business_id']);
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    $intl_timezone = $rc['settings']['intl-default-timezone'];
    $intl_currency_fmt = numfmt_create($rc['settings']['intl-default-locale'], NumberFormatter::CURRENCY);
    $intl_currency = $rc['settings']['intl-default-currency'];
    ciniki_core_loadMethod($ciniki, 'ciniki', 'users', 'private', 'dateFormat');
    ciniki_core_loadMethod($ciniki, 'ciniki', 'users', 'private', 'timeFormat');
    $date_format = ciniki_users_dateFormat($ciniki, 'php');
    $time_format = ciniki_users_timeFormat($ciniki, 'php');
    $mysql_date_format = ciniki_users_dateFormat($ciniki, 'mysql');
    //
    // Load conference maps
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'conferences', 'private', 'maps');
    $rc = ciniki_conferences_maps($ciniki);
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    $maps = $rc['maps'];
    $strsql = "SELECT ciniki_conferences.id, " . "ciniki_conferences.name, " . "ciniki_conferences.permalink, " . "ciniki_conferences.status, " . "ciniki_conferences.status AS status_text, " . "ciniki_conferences.flags, " . "DATE_FORMAT(ciniki_conferences.start_date, '" . ciniki_core_dbQuote($ciniki, $mysql_date_format) . "') AS start_date, " . "DATE_FORMAT(ciniki_conferences.end_date, '" . ciniki_core_dbQuote($ciniki, $mysql_date_format) . "') AS end_date, " . "ciniki_conferences.synopsis, " . "ciniki_conferences.description, " . "ciniki_conferences.imap_mailbox, " . "ciniki_conferences.imap_username, " . "ciniki_conferences.imap_password, " . "ciniki_conferences.imap_subject " . "FROM ciniki_conferences " . "WHERE ciniki_conferences.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND ciniki_conferences.id = '" . ciniki_core_dbQuote($ciniki, $args['conference_id']) . "' " . "";
    $rc = ciniki_core_dbHashQuery($ciniki, $strsql, 'ciniki.conferences', 'conference');
    if ($rc['stat'] != 'ok') {
        return array('stat' => 'fail', 'err' => array('pkg' => 'ciniki', 'code' => '3631', 'msg' => 'Conference not found', 'err' => $rc['err']));
    }
    if (!isset($rc['conference'])) {
        return array('stat' => 'fail', 'err' => array('pkg' => 'ciniki', 'code' => '3632', 'msg' => 'Unable to find Conference'));
    }
    $conference = $rc['conference'];
    if (isset($maps['conference']['status'][$conference['status_text']])) {
        $conference['status_text'] = $maps['conference']['status'][$conference['status_text']];
    }
    $strsql = "SELECT ciniki_conferences_sessions.id, " . "CONCAT_WS('-', ciniki_conferences_sessions.id, ciniki_conferences_presentations.id) AS rowid, " . "ciniki_conferences_sessions.conference_id, " . "ciniki_conferences_sessions.room_id, " . "ciniki_conferences_rooms.name AS room, " . "ciniki_conferences_rooms.sequence, " . "ciniki_conferences_sessions.name, " . "ciniki_conferences_sessions.session_start AS start_time, " . "ciniki_conferences_sessions.session_start AS start_date, " . "ciniki_conferences_sessions.session_end AS end_time, " . "IFNULL(ciniki_conferences_presentations.id, 0) AS presentation_id, " . "IFNULL(ciniki_conferences_presentations.customer_id, 0) AS customer_id, " . "IFNULL(ciniki_conferences_presentations.presentation_number, '') AS presentation_number, " . "IFNULL(ciniki_conferences_presentations.title, '') AS presentation_title, " . "IFNULL(ciniki_conferences_presentations.description, '') AS presentation_description, " . "IFNULL(ciniki_customers.display_name, '') AS display_name, " . "IFNULL(ciniki_conferences_presentations.status, 0) AS status, " . "IFNULL(ciniki_conferences_presentations.status, '') AS status_text, " . "IFNULL(ciniki_conferences_attendees.status, 0) AS registration, " . "IFNULL(ciniki_conferences_attendees.status, 0) AS registration_text " . "FROM ciniki_conferences_sessions " . "INNER JOIN ciniki_conferences_rooms ON (" . "ciniki_conferences_sessions.room_id = ciniki_conferences_rooms.id " . "AND ciniki_conferences_rooms.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . ") " . "LEFT JOIN ciniki_conferences_presentations ON (" . "ciniki_conferences_sessions.id = ciniki_conferences_presentations.session_id " . "AND ciniki_conferences_presentations.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . ") " . "LEFT JOIN ciniki_conferences_attendees ON (" . "ciniki_conferences_presentations.customer_id = ciniki_conferences_attendees.customer_id " . "AND ciniki_conferences_presentations.conference_id = ciniki_conferences_attendees.conference_id " . "AND ciniki_conferences_attendees.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . ") " . "LEFT JOIN ciniki_customers ON (" . "ciniki_conferences_presentations.customer_id = ciniki_customers.id " . "AND ciniki_customers.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . ") " . "WHERE ciniki_conferences_sessions.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND ciniki_conferences_sessions.conference_id = '" . ciniki_core_dbQuote($ciniki, $args['conference_id']) . "' " . "ORDER BY ciniki_conferences_sessions.session_start, " . "ciniki_conferences_rooms.name, " . "ciniki_conferences_rooms.sequence, " . "ciniki_conferences_presentations.title " . "";
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbHashQueryArrayTree');
    $rc = ciniki_core_dbHashQueryArrayTree($ciniki, $strsql, 'ciniki.conferences', array(array('container' => 'times', 'fname' => 'start_time', 'fields' => array('start_time', 'start_date', 'end_time'), 'utctotz' => array('start_time' => array('format' => $time_format, 'timezone' => $intl_timezone), 'start_date' => array('format' => $date_format, 'timezone' => $intl_timezone), 'end_time' => array('format' => $time_format, 'timezone' => $intl_timezone))), array('container' => 'rooms', 'fname' => 'room_id', 'fields' => array('id' => 'room_id', 'name' => 'room', 'session_name' => 'name', 'presentation_id')), array('container' => 'presentations', 'fname' => 'presentation_id', 'fields' => array('id', 'conference_id', 'room_id', 'room', 'sequence', 'name', 'start_time', 'start_date', 'end_time', 'presentation_id', 'customer_id', 'presentation_number', 'presentation_title', 'presentation_description', 'display_name', 'status', 'status_text', 'registration', 'registration_text'), 'utctotz' => array('start_time' => array('format' => $time_format, 'timezone' => $intl_timezone), 'start_date' => array('format' => $date_format, 'timezone' => $intl_timezone), 'end_time' => array('format' => $time_format, 'timezone' => $intl_timezone)), 'maps' => array('status_text' => $maps['presentation']['status'], 'registration_text' => $maps['attendee']['status']))));
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    if (isset($rc['times'])) {
        $timeslots = $rc['times'];
    } else {
        $timeslots = array();
    }
    //
    // Generate the word file
    //
    require_once $ciniki['config']['core']['lib_dir'] . '/PHPWord/src/PhpWord/Autoloader.php';
    \PhpOffice\PhpWord\Autoloader::register();
    require $ciniki['config']['core']['lib_dir'] . '/PHPWord/src/PhpWord/PhpWord.php';
    $PHPWord = new \PhpOffice\PhpWord\PhpWord();
    $PHPWord->addTitleStyle(1, array('bold' => true, 'size' => 18), array('spaceBefore' => 240, 'spaceAfter' => 120));
    $PHPWord->addTitleStyle(2, array('bold' => true, 'size' => 16), array('spaceBefore' => 120, 'spaceAfter' => 120));
    $PHPWord->addTitleStyle(3, array('bold' => false, 'size' => 14), array('spaceBefore' => 120, 'spaceAfter' => 120));
    $style_table = array('cellMargin' => 80, 'borderColor' => 'aaaaaa', 'borderSize' => 6);
    $style_header = array('borderSize' => 6, 'borderColor' => 'aaaaaa', 'bgColor' => 'dddddd', 'valign' => 'center');
    $style_cell = array('borderSize' => 6, 'borderColor' => 'aaaaaa', 'valign' => 'center', 'bgcolor' => 'ffffff');
    $style_header_font = array('bold' => true, 'spaceAfter' => 20);
    $style_cell_font = array();
    $style_header_pleft = array('align' => 'left');
    $style_header_pright = array('align' => 'right');
    $style_cell_pleft = array('align' => 'left');
    $style_cell_pright = array('align' => 'right');
    $section = $PHPWord->addSection();
    $header = $section->addHeader();
    $table = $header->addTable();
    $table->addRow();
    $cell = $table->addCell(9600);
    $cell->addText($conference['name'], array('size' => '16'), array('align' => 'center'));
    //print "<pre>" . print_r($timeslots, true) . "</pre>";
    //exit;
    //
    // Create a table with a row for each time slot
    //
    $cur_date = '';
    $table = $section->addTable($style_table);
    $session_number = 1;
    foreach ($timeslots as $timeslot) {
        //
        // Add the date as a header
        //
        if ($timeslot['start_date'] != $cur_date) {
            $table->addRow();
            $cell = $table->addCell(1500, $style_cell);
            $cell->addText($timeslot['start_date']);
            $cell->setGridSpan(2);
            $cur_date = $timeslot['start_date'];
            //            $session_number = 1;
        }
        //
        // Add the time slot
        //
        $table->addRow();
        $cell = $table->addCell(1500, $style_cell);
        $cell->addText($timeslot['start_time'] . ' - ' . $timeslot['end_time'], $style_cell_font);
        $nonsession_info = array();
        $session_info = array();
        if (isset($timeslot['rooms']) && count($timeslot['rooms']) > 0) {
            foreach ($timeslot['rooms'] as $room) {
                if (!isset($room['presentations']) || $room['presentation_id'] == 0) {
                    if (isset($room['presentations'][0])) {
                        $session = $room['presentations'][0];
                        if ($session['name'] != '') {
                            $nonsession_info[] = $session['name'];
                        }
                    }
                    $nonsession_info[] = "Location: " . $room['name'];
                } else {
                    $session_info[] = $session_number . ". " . $room['session_name'] . ": ";
                    $presentation_number = 1;
                    $presentation_info = '';
                    foreach ($room['presentations'] as $presentation) {
                        if ($presentation_number > 1) {
                            $presentation_info .= "; ";
                        }
                        $presentation_info .= $presentation_number . ") " . $presentation['display_name'];
                        $presentation_number++;
                    }
                    $session_info[] = $presentation_info;
                    $session_info[] = "Location: " . $room['name'];
                    $session_info[] = "";
                    $session_number++;
                }
            }
        }
        $cell = $table->addCell(2500, $style_cell);
        foreach ($nonsession_info as $line) {
            $cell->addText($line, $style_cell_font);
        }
        $cell = $table->addCell(5500, $style_cell);
        foreach ($session_info as $line) {
            $cell->addText($line, $style_cell_font);
        }
    }
    $section = $PHPWord->addSection();
    $header = $section->addHeader();
    $table = $header->addTable();
    $table->addRow();
    $cell = $table->addCell(9600);
    $cell->addText($conference['name'], array('size' => '16'), array('align' => 'center'));
    $session_number = 1;
    foreach ($timeslots as $timeslot) {
        if (isset($timeslot['rooms']) && count($timeslot['rooms']) > 0) {
            foreach ($timeslot['rooms'] as $room) {
                if (!isset($room['presentations']) || $room['presentation_id'] == 0) {
                    continue;
                }
                $section->addTitle($session_number . ". " . $room['session_name'], 1);
                if (isset($room['presentations']) && $room['presentation_id'] != 0) {
                    foreach ($room['presentations'] as $pid => $presentation) {
                        $section->addTitle($presentation['display_name'], 2);
                        $section->addTitle(htmlspecialchars($presentation['presentation_title']), 3);
                        $lines = explode("\n", $presentation['presentation_description']);
                        foreach ($lines as $line) {
                            $section->addText(htmlspecialchars($line), array());
                        }
                        $section->addText('');
                    }
                }
                $session_number++;
            }
        }
    }
    //
    // Output the word file
    //
    header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
    header('Content-Disposition: attachment;filename="' . preg_replace("/[^A-Za-z0-9]/", '', $conference['name']) . '.docx"');
    header('Cache-Control: max-age=0');
    $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($PHPWord, 'Word2007');
    $objWriter->save('php://output');
    return array('stat' => 'exit');
}
Beispiel #3
0
function ciniki_conferences_presentationGet($ciniki)
{
    //
    // Find all the required and optional arguments
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'prepareArgs');
    $rc = ciniki_core_prepareArgs($ciniki, 'no', array('business_id' => array('required' => 'yes', 'blank' => 'no', 'name' => 'Business'), 'presentation_id' => array('required' => 'yes', 'blank' => 'no', 'name' => 'Presentation')));
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    $args = $rc['args'];
    //
    // Make sure this module is activated, and
    // check permission to run this function for this business
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'conferences', 'private', 'checkAccess');
    $rc = ciniki_conferences_checkAccess($ciniki, $args['business_id'], 'ciniki.conferences.presentationGet');
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    //
    // Load business settings
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'businesses', 'private', 'intlSettings');
    $rc = ciniki_businesses_intlSettings($ciniki, $args['business_id']);
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    $intl_timezone = $rc['settings']['intl-default-timezone'];
    $intl_currency_fmt = numfmt_create($rc['settings']['intl-default-locale'], NumberFormatter::CURRENCY);
    $intl_currency = $rc['settings']['intl-default-currency'];
    ciniki_core_loadMethod($ciniki, 'ciniki', 'users', 'private', 'datetimeFormat');
    ciniki_core_loadMethod($ciniki, 'ciniki', 'users', 'private', 'dateFormat');
    ciniki_core_loadMethod($ciniki, 'ciniki', 'users', 'private', 'timeFormat');
    $datetime_format = ciniki_users_datetimeFormat($ciniki, 'php');
    $date_format = ciniki_users_dateFormat($ciniki, 'php');
    $time_format = ciniki_users_timeFormat($ciniki, 'php');
    //
    // Load conference maps
    //
    ciniki_core_loadMethod($ciniki, 'ciniki', 'conferences', 'private', 'maps');
    $rc = ciniki_conferences_maps($ciniki);
    if ($rc['stat'] != 'ok') {
        return $rc;
    }
    $maps = $rc['maps'];
    //
    // Return default for new Presentation
    //
    if ($args['presentation_id'] == 0) {
        $presentation = array('id' => 0, 'conference_id' => '', 'customer_id' => '', 'session_id' => 0, 'presentation_number' => '', 'presentation_type' => '', 'status' => '10', 'registration' => '0', 'submission_date' => '', 'field' => '', 'title' => '', 'permalink' => '', 'description' => '');
        $sessions = array();
    } else {
        $strsql = "SELECT ciniki_conferences_presentations.id, " . "ciniki_conferences_presentations.conference_id, " . "ciniki_conferences_presentations.customer_id, " . "ciniki_conferences_presentations.session_id, " . "ciniki_customers.display_name, " . "ciniki_conferences_presentations.presentation_number, " . "ciniki_conferences_presentations.presentation_type, " . "ciniki_conferences_presentations.presentation_type AS presentation_type_text, " . "ciniki_conferences_presentations.status, " . "ciniki_conferences_presentations.status AS status_text, " . "IFNULL(ciniki_conferences_attendees.status, 0) AS registration, " . "IFNULL(ciniki_conferences_attendees.status, 0) AS registration_text, " . "ciniki_conferences_presentations.submission_date, " . "ciniki_conferences_presentations.field, " . "ciniki_conferences_presentations.title, " . "ciniki_conferences_presentations.permalink, " . "ciniki_conferences_presentations.description " . "FROM ciniki_conferences_presentations " . "LEFT JOIN ciniki_conferences_attendees ON (" . "ciniki_conferences_presentations.customer_id = ciniki_conferences_attendees.customer_id " . "AND ciniki_conferences_attendees.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . ") " . "LEFT JOIN ciniki_customers ON (" . "ciniki_conferences_presentations.customer_id = ciniki_customers.id " . "AND ciniki_customers.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . ") " . "WHERE ciniki_conferences_presentations.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND ciniki_conferences_presentations.id = '" . ciniki_core_dbQuote($ciniki, $args['presentation_id']) . "' " . "";
        ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbHashQueryArrayTree');
        $rc = ciniki_core_dbHashQueryArrayTree($ciniki, $strsql, 'ciniki.conferences', array(array('container' => 'presentations', 'fname' => 'id', 'fields' => array('id', 'conference_id', 'customer_id', 'session_id', 'display_name', 'presentation_number', 'presentation_type', 'presentation_type_text', 'status', 'status_text', 'registration', 'registration_text', 'submission_date', 'field', 'title', 'permalink', 'description'), 'maps' => array('presentation_type_text' => $maps['presentation']['presentation_type'], 'status_text' => $maps['presentation']['status'], 'registration_text' => $maps['attendee']['status']), 'utctotz' => array('submission_date' => array('format' => $datetime_format, 'timezone' => $intl_timezone)))));
        if ($rc['stat'] != 'ok') {
            return array('stat' => 'fail', 'err' => array('pkg' => 'ciniki', 'code' => '3081', 'msg' => 'Presentation not found', 'err' => $rc['err']));
        }
        if (!isset($rc['presentations'][0])) {
            return array('stat' => 'fail', 'err' => array('pkg' => 'ciniki', 'code' => '3082', 'msg' => 'Unable to find Presentation'));
        }
        $presentation = $rc['presentations'][0];
        $presentation['display_title'] = sprintf("#%03d: ", $presentation['presentation_number']) . $presentation['title'];
        //
        // Get the customer details
        //
        ciniki_core_loadMethod($ciniki, 'ciniki', 'customers', 'hooks', 'customerDetails');
        $rc = ciniki_customers_hooks_customerDetails($ciniki, $args['business_id'], array('customer_id' => $presentation['customer_id'], 'phones' => 'yes', 'emails' => 'yes', 'addresses' => 'no', 'subscriptions' => 'no', 'full_bio' => 'yes'));
        if ($rc['stat'] != 'ok') {
            return $rc;
        }
        $presentation['customer_details'] = $rc['details'];
        if (isset($rc['customer']['full_bio'])) {
            $presentation['full_bio'] = $rc['customer']['full_bio'];
        } else {
            $presentation['full_bio'] = '';
        }
        //
        // Lookup reviews
        //
        $strsql = "SELECT ciniki_conferences_presentation_reviews.id, " . "ciniki_conferences_presentation_reviews.conference_id, " . "ciniki_conferences_presentation_reviews.customer_id, " . "ciniki_customers.display_name, " . "ciniki_conferences_presentation_reviews.vote, " . "ciniki_conferences_presentation_reviews.vote AS vote_text " . "FROM ciniki_conferences_presentation_reviews " . "LEFT JOIN ciniki_customers ON (" . "ciniki_conferences_presentation_reviews.customer_id = ciniki_customers.id " . "AND ciniki_customers.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . ") " . "WHERE ciniki_conferences_presentation_reviews.presentation_id = '" . ciniki_core_dbQuote($ciniki, $args['presentation_id']) . "' " . "AND ciniki_conferences_presentation_reviews.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "";
        $rc = ciniki_core_dbHashQueryArrayTree($ciniki, $strsql, 'ciniki.conferences', array(array('container' => 'reviews', 'fname' => 'id', 'fields' => array('id', 'conference_id', 'customer_id', 'display_name', 'vote', 'vote_text'), 'maps' => array('vote_text' => $maps['presentationreview']['vote']))));
        if ($rc['stat'] != 'ok') {
            return array('stat' => 'fail', 'err' => array('pkg' => 'ciniki', 'code' => '3188', 'msg' => 'Unable to get list of reviews', 'err' => $rc['err']));
        }
        if (isset($rc['reviews'])) {
            $presentation['reviews'] = $rc['reviews'];
        } else {
            $presentation['reviews'] = array();
        }
        //
        // Get the list of sessions
        //
        $strsql = "SELECT ciniki_conferences_sessions.id, " . "ciniki_conferences_sessions.conference_id, " . "ciniki_conferences_sessions.room_id, " . "ciniki_conferences_sessions.name, " . "ciniki_conferences_rooms.name AS room, " . "ciniki_conferences_rooms.sequence, " . "ciniki_conferences_sessions.session_start AS start_time, " . "ciniki_conferences_sessions.session_start AS start_date, " . "ciniki_conferences_sessions.session_end AS end_time " . "FROM ciniki_conferences_sessions " . "LEFT JOIN ciniki_conferences_rooms ON (" . "ciniki_conferences_sessions.room_id = ciniki_conferences_rooms.id " . "AND ciniki_conferences_rooms.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . ") " . "WHERE ciniki_conferences_sessions.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND ciniki_conferences_sessions.conference_id = '" . ciniki_core_dbQuote($ciniki, $presentation['conference_id']) . "' " . "";
        ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbHashQueryArrayTree');
        $rc = ciniki_core_dbHashQueryArrayTree($ciniki, $strsql, 'ciniki.conferences', array(array('container' => 'sessions', 'fname' => 'id', 'fields' => array('id', 'conference_id', 'room', 'room_id', 'name', 'sequence', 'start_time', 'start_date', 'end_time'), 'utctotz' => array('start_time' => array('format' => $time_format, 'timezone' => $intl_timezone), 'start_date' => array('format' => $date_format, 'timezone' => $intl_timezone), 'end_time' => array('format' => $time_format, 'timezone' => $intl_timezone)))));
        if ($rc['stat'] != 'ok') {
            return $rc;
        }
        if (isset($rc['sessions'])) {
            $sessions = $rc['sessions'];
            foreach ($sessions as $sid => $session) {
                $sessions[$sid]['display_name'] = $session['name'];
                if ($session['room'] != '') {
                    $sessions[$sid]['display_name'] .= ($sessions[$sid]['display_name'] != '' ? ' - ' : '') . $session['room'];
                }
                $sessions[$sid]['display_name'] .= ($sessions[$sid]['display_name'] != '' ? ' - ' : '') . $session['start_time'] . ' - ' . $session['end_time'] . ', ' . $session['start_date'];
            }
        } else {
            $sessions = array();
        }
    }
    return array('stat' => 'ok', 'presentation' => $presentation, 'sessions' => $sessions);
}