function extract_file($file_comp, $file_target) { while (!$file_comp->eof()) { $byte = $file_comp->fread(1); $count = $file_comp->fread(1); display_percent($file_comp); if ($file_comp->eof()) { break; } $count = unpack('C', $count); $count = array_shift($count); // $s = bin2hex($byte); // echo "{$s}:{$count}\n"; for ($i = 0; $i < $count; $i++) { $file_target->fwrite($byte); } } }
function display_menu($view_user_id, $folder_id) { global $db, $template, $lang, $images, $board_config; global $main_pgm; global $folders; global $s_unread; // folder management if (defined('IN_FOLDERS')) { display_menu_folders($view_user_id, $folder_id); return; } // no folder granted if (empty($folders['data'][$folder_id])) { $folder_id = INBOX; } $folder_main = $folder_id; if (!empty($folders['main'][$folder_id])) { $folder_main = $folders['main'][$folder_id]; } // get main folders $mains = array(); @reset($folders['data']); while (list($id, $data) = @each($folders['data'])) { if (empty($folders['main'][$id])) { $mains[] = $id; } } // count new/unread messages $count_messages = array(); //------------------------------ // count mails per box //------------------------------ for ($i = 0; $i < count($mains); $i++) { $sql_where = ''; switch ($mains[$i]) { case INBOX: $sql_where = "privmsg_direct = 1 AND privmsg_status = " . STS_TRANSIT; break; case OUTBOX: $sql_where = "privmsg_direct = 0 AND privmsg_read IN ({$s_unread}) AND privmsg_status = " . STS_TRANSIT; break; case SENTBOX: $sql_where = "privmsg_direct = 0 AND privmsg_read = " . READ_MAIL . " AND privmsg_status = " . STS_TRANSIT; break; case SAVEBOX: $sql_where = "privmsg_status = " . STS_SAVED; break; } // base sql $sql_box = "SELECT privmsg_folder_id, count(privmsg_id) AS count_messages\n FROM " . PRIVMSGA_RECIPS_TABLE . "\n WHERE privmsg_user_id = {$view_user_id}\n AND {$sql_where}"; // count all in a box $sql = $sql_box . " GROUP BY privmsg_folder_id"; if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Could not count messages from box', '', __LINE__, __FILE__, $sql); } while ($row = $db->sql_fetchrow($result)) { $count_messages['local'][$row['privmsg_folder_id']] = $row['count_messages']; } // count unread $sql = $sql_box . " AND privmsg_read IN ({$s_unread}) GROUP BY privmsg_folder_id"; if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Could not count unread messages', '', __LINE__, __FILE__, $sql); } while ($row = $db->sql_fetchrow($result)) { $count_messages['local_unread'][$row['privmsg_folder_id']] = $row['count_messages']; } } // sum the message to the main folder : total @reset($count_messages['local']); while (list($id, $count) = @each($count_messages['local'])) { $main_id = $id; if (!empty($folders['main'][$id])) { $main_id = $folders['main'][$id]; } $count_messages['main'][$main_id] += $count; } // sum the message to the main folder : unread @reset($count_messages['local_unread']); while (list($id, $count) = @each($count_messages['local_unread'])) { $main_id = $id; if (!empty($folders['main'][$id])) { $main_id = $folders['main'][$id]; } $count_messages['main_unread'][$main_id] += $count; } //------------------------------ // process //------------------------------ // build the tree $template->set_filenames(array('privmsga_folders_box' => 'privmsga_folders_box.tpl')); $template->assign_vars(array('L_FOLDERS' => _lang('Folders'))); $template->assign_block_vars('folders_box', array('U_SEARCH' => append_sid("{$main_pgm}&pmmode=search&folder={$folder_id}&" . POST_USERS_URL . "={$view_user_id}"), 'L_SEARCH' => _lang('Search'), 'IMG_SEARCH' => _images('icon_search'), 'U_EDIT' => append_sid("{$main_pgm}&pmmode=flist&folder={$folder_id}&" . POST_USERS_URL . "={$view_user_id}"), 'L_EDIT' => _lang('Edit'), 'IMG_EDIT' => _images('icon_folder_edit'))); for ($i = 0; $i < count($mains); $i++) { // add the main level $id = $mains[$i]; $name = _lang($folders['data'][$id]['folder_name']); if ($id == $folder_id) { $name = sprintf('<b>%s</b>', $name); } // counts $count = 0; $count_unread = 0; if ($id == $folder_id || $id == $folder_main) { // we are on the select box : use local count if ($count_messages['local'][$id] > 0) { $count = $count_messages['local'][$id]; } if ($count_messages['local_unread'][$id] > 0) { $count_unread = $count_messages['local_unread'][$id]; } } else { // we are on a non-selected box : use sum count if ($count_messages['main'][$id] > 0) { $count = $count_messages['main'][$id]; } if ($count_messages['main_unread'][$id] > 0) { $count_unread = $count_messages['main_unread'][$id]; } } // icon $img = 'icon_minipost'; if ($count_unread > 0) { $img = 'icon_minipost_new'; } // display main folder $template->assign_block_vars('folders_box.main', array('COLOR' => $id == $folder_id || $id == $folder_main ? 'row1' : 'row2', 'IMG_FOLDER' => _images($img), 'U_FOLDER' => append_sid("{$main_pgm}&folder={$id}"), 'L_FOLDER' => $name, 'COUNT' => sprintf('(%d)', $count), 'COUNT_UNREAD' => sprintf('(%d)', $count_unread))); $template->assign_block_vars('folders_box.main.no_manage', array()); // add sublevels if ($id == $folder_main) { $sub_exist = false; for ($j = 0; $j < count($folders['sub'][$mains[$i]]); $j++) { $sub_exist = true; $id = $folders['sub'][$mains[$i]][$j]; $name = _lang($folders['data'][$id]['folder_name']); if ($id == $folder_id) { $name = sprintf('<b>%s</b>', $name); } // counts $count = 0; $count_unread = 0; // we are on the select box : use local count if ($count_messages['local'][$id] > 0) { $count = $count_messages['local'][$id]; } if ($count_messages['local_unread'][$id] > 0) { $count_unread = $count_messages['local_unread'][$id]; } // icon $img = 'icon_minipost'; if ($count_unread > 0) { $img = 'icon_minipost_new'; } $template->assign_block_vars('folders_box.main.sub', array('IMG_FOLDER' => _images($img), 'U_FOLDER' => append_sid("{$main_pgm}&folder={$id}"), 'L_FOLDER' => $name, 'COUNT' => sprintf('(%d)', $count), 'COUNT_UNREAD' => sprintf('(%d)', $count_unread))); $template->assign_block_vars('folders_box.main.sub.no_manage', array()); } if ($sub_exist) { $template->assign_block_vars('folders_box.main.sub_exist', array()); } } } $template->assign_block_vars('folders_box.switch_search', array()); $template->assign_block_vars('folders_box.switch_no_manage', array()); display_percent($view_user_id, $folder_main, $count_messages['main'][$folder_main]); $template->assign_var_from_handle('FOLDERS_BOX', 'privmsga_folders_box'); }