function games_admin_draw($options) { $slot_1_start = strtotime('10:30'); $slot_1_end = strtotime('11:30'); $slot_2_start = strtotime('17:30'); $slot_2_end = strtotime('18:30'); // echo date('Y-m-d H:i', $slot_1_start) . '<br />'; // echo date('Y-m-d H:i', $slot_1_end) . '<br />'; // echo date('Y-m-d H:i', $slot_2_start) . '<br />'; // echo date('Y-m-d H:i', $slot_2_end) . '<br />'; // unset($game); if (isset($options['game'])) { $game = $options['game']; } else { /*------------------------------------------------------------------------------------*/ $config['new_game'][0]['start'] = strtotime('07:00'); $config['new_game'][0]['end'] = strtotime('09:15'); $config['new_game'][1]['start'] = strtotime('16:00'); $config['new_game'][1]['end'] = strtotime('21:30'); $type = 'new_game'; $slots = $config[$type]; $num_of_slots = count($slots); $slot = 0; $day = 0; /* Offset, days counting from today */ $midnight = strtotime(date('Y-m-d')); $time = time(); unset($free_slot); echo 'time: ' . $time . ' ' . date('Y-m-d H:i', $time) . '<br />'; echo 'after: ' . $options['after'] . ' ' . date('Y-m-d H:i', $options['after']) . '<br />'; echo 'type: ' . $type . '<br />'; echo date('Y-m-d H:i', $slots[$slot]['end'] + $day * 86400) . '<br />'; /* Find the next slot, regardless if it's occupied or not */ while ($slots[$slot]['start'] + $day * 86400 <= $time) { echo 'slot before time <br />'; $slot++; if ($slot >= $num_of_slots) { $day++; $slot = 0; } } echo 'Find nearest slot after day #' . $day . ', slot #' . $slot . '<br />'; $query = 'SELECT `release` FROM games WHERE `release` > "' . $time . '" ORDER BY `release` ASC'; $result = mysql_query($query) or die(report_sql_error($query, __FILE__, __LINE__)); echo 'Items in qeue: ' . mysql_num_rows($result) . '<br />'; if ($data = mysql_fetch_assoc($result)) { $release = $data['release']; echo 'before loop, release: ' . $release . ' ' . date('Y-m-d H:i', $release) . '<br />'; while (!isset($free_slot)) { if ($release < $slots[$slot]['start'] + $day * 86400) { echo 'Released before current slot' . "\n"; if ($data = mysql_fetch_assoc($result)) { $release = $data['release']; } else { $free_slot = $slot; } } elseif ($release < $slots[$slot]['end'] + $day * 86400) { $slot++; if ($slot >= $num_of_slots) { $day++; $slot = 0; } if ($data = mysql_fetch_assoc($result)) { $release = $data['release']; } else { $free_slot = $slot; } } else { $free_slot = $slot; } } } // preint_r($slots); echo 'slot: ' . $slot . '<br />'; echo 'day: ' . $day . '<br />'; $next_release = $slots[$slot]['start'] + $day * 86400 + rand(0, $slots[$slot]['end'] - $slots[$slot]['start']); } /*--------------------------------------------------------------------------------------------------------------*/ /* preint_r($game); */ global $game_tags; echo '<form id="game_edit_form" method="post" action="/spel/' . (isset($options['game_new']) ? 'nytt_spel' : 'redigera') . '_spara.php" enctype="multipart/form-data">' . "\n"; echo '<h5>Titel</h5>' . "\n"; echo '<input type="text" name="title" value="' . (isset($game) ? $game['title'] : '') . '" />' . "\n"; if (isset($game)) { echo '<input type="hidden" name="handle" value="' . $game['handle'] . '" />' . "\n"; } echo '<h5>Taggar</h5>' . "\n"; $tags_all = tag_get_by_handle($game_tags); echo '<ul>' . "\n"; foreach ($tags_all as $tag) { echo '<li>' . "\n"; echo '<img alt="' . $tag['label'] . '" class="games_tag" id="games_tag_' . $tag['handle'] . '" src="' . IMAGE_URL . 'games/tags/' . $tag['handle'] . '.png" />' . "\n"; echo '<br />'; echo '<input type="checkbox" name="chk_tag_' . $tag['handle'] . '" id="chk_tag_' . $tag['handle'] . '" name="tags"'; if (isset($game)) { echo array_key_exists($tag['handle'], $game['tags']) ? ' checked="checked" ' : ''; } echo '>' . '' . '</input>' . "\n"; // echo '<label for="chk_tag_' . $tag['handle'] . '">' . "\n"; // echo '</label>' . "\n"; echo '<li>' . "\n"; } echo '</ul>' . "\n"; foreach ($game['tags'] as $tag) { if (!array_key_exists($tag['handle'], $tags_all)) { $extra_tags_labels[] = $tag['label']; } } echo '<h5>Nyckelord för övriga taggar (separerade med mellanslag)</h5>' . "\n"; echo '<textarea name="tags" rows="3" cols="60" >' . (isset($game) ? implode(', ', $extra_tags_labels) : '') . '</textarea>' . "\n"; echo '<h5>Beskrivning</h5>' . "\n"; echo '<textarea name="description" rows="6" cols="60" >' . (isset($game) ? $game['description'] : '') . '</textarea>' . "\n"; /* Added by Johan at 2007-09-23 10:00 */ echo '<h5>Bild (skalas och konverteras automagiskt)</h5>' . "\n"; echo '<input name="thumbnail" type="file" />' . "\n"; echo '<h5>Release</h5>' . "\n"; echo '<p>ex 2008-12-24, ' . $next_release . '</p>'; echo '<input type="text" name="release" value="' . (isset($game['release']) ? date('Y-m-d h:i', $game['release']) : date('Y-m-d H:i', $next_release)) . '" />' . "\n"; echo '<input type="checkbox" name="release_now" value="true" id="release_now_check" />' . "\n"; echo '<label for="release_now_check">Släpp spelet direkt</label>' . "\n"; echo '<h5>Kontroller</h5>' . "\n"; echo '<table>' . "\n"; for ($i = 0; $i < 8; $i++) { echo '<tr>' . "\n"; echo '<td><input type="text" name="key_' . $i . '" value="' . (isset($game) ? $game['controls'][$i]['combination'] : '') . '"></td>'; echo '<td><input type="text" name="action_' . $i . '" value="' . (isset($game) ? $game['controls'][$i]['description'] : '') . '"></td>'; echo '</tr>' . "\n"; } echo '</table>' . "\n"; echo '<input type="checkbox", value="delete" id="chk_game_delete" name="delete" />'; echo '<label for="chk_game_delete">Ta bort spelet</label>'; echo '<h5>Highscore gname (låt bli om du inte vet vad detta är!)</h5>' . "\n"; echo '<input type="text" name="highscore_gname" value="' . $game['highscore_gname'] . '" /><br />' . "\n"; echo '<input type="submit" value="Spara" class="button_60" style="border: none;" />' . "\n"; echo '</form>' . "\n"; }
function tag_set_wrap($options) { /* Obs! Removes all old tags options array support possible values item_id no object_type no 'discussion', 'post', 'wallpaper', 'article', 'survey', 'game', 'clip', 'a1' tag_handle yes handle_type_values tag_label yes Free text values tag_id yes 1, 2, 3.. add no set to true if tags should be added to old tags */ if (644314 == $_SESSION['login']['id']) { preint_r($options); } $keys = array('tag_handle', 'tag_label', 'tag_id'); foreach ($keys as $key) { if (isset($options[$key])) { $options[$key] = is_array($options[$key]) ? $options[$key] : array($options[$key]); $keytype = $key; } } if ($keytype == 'tag_label') { foreach ($options['tag_label'] as $label) { if (!($tag = tag_get_by_handle(url_secure_string($label)))) { $tag_id = tag_create($label); } else { $tag_id = $tag['id']; } $tag_ids[] = $tag_id; } } elseif ($keytype == 'tag_handle') { $tags = tag_get_by_handle($options['tag_handle']); unset($tag_ids); foreach ($tags as $tag) { $tag_ids[] = $tag['id']; } } if (!isset($options['add'])) { $query = 'DELETE FROM object_tags WHERE object_type = "' . $options['object_type'] . '" AND reference_id = "' . $options['item_id'] . '"'; mysql_query($query); } foreach ($tag_ids as $tag_id) { $query = 'INSERT INTO object_tags (tag_id, object_type, reference_id)'; $query .= ' VALUES ("' . $tag_id . '", "' . $options['object_type'] . '", "' . $options['item_id'] . '")'; mysql_query($query); //todo! annan felhantering här då det kan hända att man försöker sätta redan satta taggar, or die(report_sql_error($query, __FILE__, __LINE__)); } }