<?php require_once 'src/model/Scenario.php'; require_once 'src/model/Approximation.php'; require_once "libs/vmwarephp/Bootstrap.php"; ini_set('xdebug.max_nesting_level', 3000); $vmware = new \Vmwarephp\Vhost(getenv('VMHOST'), getenv('VMUSER'), getenv('VMPASS')); define('FNVM', "SeTIC_VMs.json"); define('FNPM', "SeTIC_PMs.json"); define('FNPL', "SeTIC_Placements.json"); define('FNSC', "SeTIC_Scenario.json"); if (!file_exists(FNVM)) { loadVMs($vmware); } if (!file_exists(FNPM)) { loadPMs($vmware); } if (!file_exists(FNPL)) { convertDataToPlacements(); } if (!file_exists(FNSC)) { convertPlacementToScenario(); } $pms = json_decode(file(FNPM)[0], true); $vms = json_decode(file(FNVM)[0], true); $scenario = json_decode(file(FNSC)[0], true); $tmp = array(); foreach ($vms as $vm) { $tmp[$vm['name']] = 0; } $fmt = "\nVM-UUIDs(%s) | VM-Names(%s) | PMs(%s) | PossiblePlaces(%s) | APR(%s)\n";
/** * Display a folder, ie. inbox/sent etc. * * @uses folder sub template * @uses subject_list, pm template layers */ public function action_folder() { global $txt, $scripturl, $modSettings, $context, $subjects_request; global $messages_request, $user_info, $recipients, $options, $user_settings; // Changing view? if (isset($_GET['view'])) { $context['display_mode'] = $context['display_mode'] > 1 ? 0 : $context['display_mode'] + 1; updateMemberData($user_info['id'], array('pm_prefs' => $user_settings['pm_prefs'] & 252 | $context['display_mode'])); } // Make sure the starting location is valid. if (isset($_GET['start']) && $_GET['start'] !== 'new') { $start = (int) $_GET['start']; } elseif (!isset($_GET['start']) && !empty($options['view_newest_pm_first'])) { $start = 0; } else { $start = 'new'; } // Set up some basic template stuff. $context['from_or_to'] = $context['folder'] !== 'sent' ? 'from' : 'to'; $context['get_pmessage'] = 'preparePMContext_callback'; $context['signature_enabled'] = substr($modSettings['signature_settings'], 0, 1) == 1; $context['disabled_fields'] = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array(); // Set the template layers we need $template_layers = Template_Layers::getInstance(); $template_layers->addAfter('subject_list', 'pm'); $labelQuery = $context['folder'] != 'sent' ? ' AND FIND_IN_SET(' . $context['current_label_id'] . ', pmr.labels) != 0' : ''; // They didn't pick a sort, so we use the forum default. $sort_by = !isset($_GET['sort']) ? 'date' : $_GET['sort']; $descending = isset($_GET['desc']); // Set our sort by query switch ($sort_by) { case 'date': $sort_by_query = 'pm.id_pm'; $descending = !empty($options['view_newest_pm_first']); break; case 'name': $sort_by_query = 'IFNULL(mem.real_name, \'\')'; break; case 'subject': $sort_by_query = 'pm.subject'; break; default: $sort_by_query = 'pm.id_pm'; } // Set the text to resemble the current folder. $pmbox = $context['folder'] !== 'sent' ? $txt['inbox'] : $txt['sent_items']; $txt['delete_all'] = str_replace('PMBOX', $pmbox, $txt['delete_all']); // Now, build the link tree! if ($context['current_label_id'] === -1) { $context['linktree'][] = array('url' => $scripturl . '?action=pm;f=' . $context['folder'], 'name' => $pmbox); } // Build it further if we also have a label. if ($context['current_label_id'] !== -1) { $context['linktree'][] = array('url' => $scripturl . '?action=pm;f=' . $context['folder'] . ';l=' . $context['current_label_id'], 'name' => $txt['pm_current_label'] . ': ' . $context['current_label']); } // Figure out how many messages there are. $max_messages = getPMCount(false, null, $labelQuery); // Only show the button if there are messages to delete. $context['show_delete'] = $max_messages > 0; // Start on the last page. if (!is_numeric($start) || $start >= $max_messages) { $start = $max_messages - 1 - ($max_messages - 1) % $modSettings['defaultMaxMessages']; } elseif ($start < 0) { $start = 0; } // ... but wait - what if we want to start from a specific message? if (isset($_GET['pmid'])) { $pmID = (int) $_GET['pmid']; // Make sure you have access to this PM. if (!isAccessiblePM($pmID, $context['folder'] == 'sent' ? 'outbox' : 'inbox')) { fatal_lang_error('no_access', false); } $context['current_pm'] = $pmID; // With only one page of PM's we're gonna want page 1. if ($max_messages <= $modSettings['defaultMaxMessages']) { $start = 0; } elseif (!isset($_GET['kstart'])) { $start = getPMCount($descending, $pmID, $labelQuery); // To stop the page index's being abnormal, start the page on the page the message // would normally be located on... $start = $modSettings['defaultMaxMessages'] * (int) ($start / $modSettings['defaultMaxMessages']); } } // Sanitize and validate pmsg variable if set. if (isset($_GET['pmsg'])) { $pmsg = (int) $_GET['pmsg']; if (!isAccessiblePM($pmsg, $context['folder'] === 'sent' ? 'outbox' : 'inbox')) { fatal_lang_error('no_access', false); } } // Determine the navigation context $context['links'] += array('prev' => $start >= $modSettings['defaultMaxMessages'] ? $scripturl . '?action=pm;start=' . ($start - $modSettings['defaultMaxMessages']) : '', 'next' => $start + $modSettings['defaultMaxMessages'] < $max_messages ? $scripturl . '?action=pm;start=' . ($start + $modSettings['defaultMaxMessages']) : ''); $context['page_info'] = array('current_page' => $start / $modSettings['defaultMaxMessages'] + 1, 'num_pages' => floor(($max_messages - 1) / $modSettings['defaultMaxMessages']) + 1); // We now know what they want, so lets fetch those PM's list($pms, $posters, $recipients, $lastData) = loadPMs(array('sort_by_query' => $sort_by_query, 'display_mode' => $context['display_mode'], 'sort_by' => $sort_by, 'label_query' => $labelQuery, 'pmsg' => isset($pmsg) ? (int) $pmsg : 0, 'descending' => $descending, 'start' => $start, 'limit' => $modSettings['defaultMaxMessages'], 'folder' => $context['folder'], 'pmid' => isset($pmID) ? $pmID : 0), $user_info['id']); // Make sure that we have been given a correct head pm id if we are in converstation mode if ($context['display_mode'] == 2 && !empty($pmID) && $pmID != $lastData['id']) { fatal_lang_error('no_access', false); } // If loadPMs returned results, lets show the pm subject list if (!empty($pms)) { // Tell the template if no pm has specifically been selected if (empty($pmID)) { $context['current_pm'] = 0; } // This is a list of the pm's that are used for "show all" display. if ($context['display_mode'] == 0) { $display_pms = $pms; } else { $display_pms = array($lastData['id']); } // At this point we know the main id_pm's. But if we are looking at conversations we need // the PMs that make up the conversation if ($context['display_mode'] == 2) { list($display_pms, $posters) = loadConversationList($lastData['head'], $recipients, $context['folder']); // Conversation list may expose additonal PM's being displayed $all_pms = array_unique(array_merge($pms, $display_pms)); // See if any of these 'listing' PM's are in a conversation thread that has unread entries $context['conversation_unread'] = loadConversationUnreadStatus($all_pms); } else { $all_pms = array_unique(array_merge($pms, $display_pms)); } // Get recipients (don't include bcc-recipients for your inbox, you're not supposed to know :P). list($context['message_labels'], $context['message_replied'], $context['message_unread']) = loadPMRecipientInfo($all_pms, $recipients, $context['folder']); // Make sure we don't load any unnecessary data for one at a time mode if ($context['display_mode'] == 1) { foreach ($posters as $pm_key => $sender) { if (!in_array($pm_key, $display_pms)) { unset($posters[$pm_key]); } } } // Load some information about the message sender $posters = array_unique($posters); if (!empty($posters)) { loadMemberData($posters); } // If we're on grouped/restricted view get a restricted list of messages. if ($context['display_mode'] != 0) { // Get the order right. $orderBy = array(); foreach (array_reverse($pms) as $pm) { $orderBy[] = 'pm.id_pm = ' . $pm; } // Separate query for these bits, preparePMContext_callback will use it as required $subjects_request = loadPMSubjectRequest($pms, $orderBy); } // Execute the load message query if a message has been chosen and let // preparePMContext_callback fetch the results. Otherwise just show the pm selection list if (empty($pmsg) && empty($pmID) && $context['display_mode'] != 0) { $messages_request = false; } else { $messages_request = loadPMMessageRequest($display_pms, $sort_by_query, $sort_by, $descending, $context['display_mode'], $context['folder']); } } else { $messages_request = false; } // Prepare some items for the template $context['can_send_pm'] = allowedTo('pm_send'); $context['can_send_email'] = allowedTo('send_email_to_members'); $context['sub_template'] = 'folder'; $context['page_title'] = $txt['pm_inbox']; $context['sort_direction'] = $descending ? 'down' : 'up'; $context['sort_by'] = $sort_by; // Auto video embeding enabled, someone may have a link in a PM if (!empty($messages_request) && !empty($modSettings['enableVideoEmbeding'])) { addInlineJavascript(' $(document).ready(function() { $().linkifyvideo(oEmbedtext); });', true); } if (!empty($messages_request) && !empty($context['show_delete'])) { Template_Layers::getInstance()->addEnd('pm_pages_and_buttons'); } // Set up the page index. $context['page_index'] = constructPageIndex($scripturl . '?action=pm;f=' . $context['folder'] . (isset($_REQUEST['l']) ? ';l=' . (int) $_REQUEST['l'] : '') . ';sort=' . $context['sort_by'] . ($descending ? ';desc' : ''), $start, $max_messages, $modSettings['defaultMaxMessages']); $context['start'] = $start; $context['pm_form_url'] = $scripturl . '?action=pm;sa=pmactions;' . ($context['display_mode'] == 2 ? 'conversation;' : '') . 'f=' . $context['folder'] . ';start=' . $context['start'] . ($context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : ''); // Finally mark the relevant messages as read. if ($context['folder'] !== 'sent' && !empty($context['labels'][(int) $context['current_label_id']]['unread_messages'])) { // If the display mode is "old sk00l" do them all... if ($context['display_mode'] == 0) { markMessages(null, $context['current_label_id']); } elseif (!empty($context['current_pm'])) { markMessages($display_pms, $context['current_label_id']); } } // Build the conversation button array. if ($context['display_mode'] === 2 && !empty($context['current_pm'])) { $context['conversation_buttons'] = array('delete' => array('text' => 'delete_conversation', 'image' => 'delete.png', 'lang' => true, 'url' => $scripturl . '?action=pm;sa=pmactions;pm_actions%5B' . $context['current_pm'] . '%5D=delete;conversation;f=' . $context['folder'] . ';start=' . $context['start'] . ($context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '') . ';' . $context['session_var'] . '=' . $context['session_id'], 'custom' => 'onclick="return confirm(\'' . addslashes($txt['remove_message']) . '?\');"')); // Allow mods to add additional buttons here call_integration_hook('integrate_conversation_buttons'); } }