You are missing our premiere tool bar navigation system! Register and use it for FREE!

NukeCops  
•  Home •  Downloads •  Gallery •  Your Account •  Forums • 
Readme First
- Readme First! -

Read and follow the rules, otherwise your posts will be closed
Modules
· Home
· FAQ
· Buy a Theme
· Advertising
· AvantGo
· Bookmarks
· Columbia
· Community
· Donations
· Downloads
· Feedback
· Forums
· PHP-Nuke HOWTO
· Private Messages
· Search
· Statistics
· Stories Archive
· Submit News
· Surveys
· Theme Gallery
· Top
· Topics
· Your Account
Who's Online
There are currently, 68 guest(s) and 0 member(s) that are online.

You are Anonymous user. You can register for free by clicking here
Nuke Cops :: View topic - Simple question on creating a module [ ]
 Forum FAQ  •  Search  •   •  Memberlist  •  Usergroups   •  Register  •  Profile •    •  Log in to check your private messages  •  Log in

 
Post new topic  Reply to topicprinter-friendly view
View previous topic Log in to check your private messages View next topic
Author Message
ethana
Sergeant
Sergeant


Joined: Dec 26, 2005
Posts: 81


PostPosted: Mon Dec 26, 2005 2:53 pm Reply with quoteBack to top

Hello all, long time nuke user but first time module writer. I'm porting over one of my web based ftp clients i wrote a while back and im in now playing with the module structure and such. One question i have...and ill use the module Your_Account as an example...is that when i look at the code, i see that it uses $op (registered global) in a switch statement to determine what function to go to and what parameters to pass that function.

My real question is, is that when you first go into Your_Account by clicking on the link under modules...theres no op variable in the query string to tell it where to go...and since there is no op at all the switch statement is not evaluated at all so no default case is ran.

Need to know the methodology behind this so i write my module correctly to fit inside the framework. Thanks for the answers!
Find all posts by ethanaView user's profileSend private message
ethana
Sergeant
Sergeant


Joined: Dec 26, 2005
Posts: 81


PostPosted: Mon Dec 26, 2005 4:45 pm Reply with quoteBack to top

Here is what i have for code so far...any advice is appreciated!

Code:

<?php
if (!eregi("modules.php", $PHP_SELF)) {
  die ("You can't access this file directly...");
}
$index = 1;
require_once("mainfile.php");
$module_name = basename(dirname(__FILE__));
get_lang($module_name);
include("header.php");


function view ($username, $prev_directory, $curr_directory) {
  OpenTable();
  echo "<br>IN VIEW<br>";
  if (! $curr_directory) {
    $curr_directory = "\/";
  }
 
  list($ftp_conn, $ftp_username, $ftp_pass, $ftp_host) = ftp_connect_login($username); 
  if ($curr_directory) {
    $curr_list = ftp_rawlist($ftp_conn, $curr_directory);
  }
  else {
    $curr_list = ftp_rawlist($ftp_conn);
  }
 
  if((is_array($curr_list)) && (count($curr_list) > 0 )) {
    $curr_list = listing_parser($curr_list);
   
    for ($ii = 0; $ii < count($curr_list); $ii++) {
      if ((trim($listing[$i]['name']) == '..') || (trim($listing[$i]['name']) == '.')) {
        next($curr_list);
      }
      $curr_item = trim($listing[$i]['name']);
      $obj_type = substr($listing[$i]['perms'], 0, 1);     
      $next_listing = $curr_directory."\/".$curr_item;
      if ($object_type == 'd') {
        echo "<tr><td align='center'>";
        echo "<br><a href='modules.php?name=Remote_FTP&op=view&curr_directory=$next_listing&prev_directory=$curr_directory>$curr_item - <i>Folder</td></tr>";
      }
      else {
        echo "<tr><td align='center'>";
        echo "<br><a href='ftp://$ftp_username:$ftp_pass@$ftp_host$next_listing'>$curr_item</a>";// - <i>File</i> -- <a href='ftp_directory.php?main_path=$main_path&delete=$curr_folder'>Delete?</a></td></tr>";
      }
    }
  }
 
  CloseTable();
 
}
function display_ftp_table() {
}
function ftp_connect_login ($username) {
  global $db, $user_prefix;
  $results = $db->sql_query("SELECT user_id FROM ".$user_prefix." WHERE username = '$username'");
  echo "<br>Results 1: $resutls<br>";
  $row = $db->sql_fetchrow($results);
 
  $results = $db->sql_query("SELECT * FROM nuke_ftp_connect_info WHERE user_id = '$row[user_id]'");
  $row = $db->sql_fetchrow($results);
  echo "<br>Results2:<br>";
  while (list($key, $val) = each($row)) {
    echo "$key : $val<br>";
  }
 
  $usr_ftp_host = ftp_connect($row[ftp_host]);
  $login = ftp_login($usr_ftp_host, $row[ftp_username], $row[ftp_password]);
 
  set_time_limit(160);
 
  return array($usr_ftp_host, $row[ftp_username], $row[ftp_password], $row[ftp_host]);
}

function listing_parser($listing) {               
  $structure = array();
  for ( $i = 0; $i < count($listing); $i++ ) {
    $current = $listing[$i];
           
    $structure[$i]['perms']  = substr($current, 0, 10);
    $structure[$i]['number'] = trim(substr($current, 11, 3));
    $structure[$i]['owner']  = trim(substr($current, 15, 8));
    $structure[$i]['group']  = trim(substr($current, 24, 8));
    $structure[$i]['size']  = trim(substr($current, 33, 10));
    $structure[$i]['month']  = trim(substr($current, 44, 3));
    $structure[$i]['day']    = trim(substr($current, 48, 2));
    $structure[$i]['time']  = substr($current, 51, 5);
    $structure[$i]['name']  = substr($current, 56, strlen($current) - 55);#$structure[$i]['name']  = substr($current, 56, strlen($current) - 55);
    echo '<br>name: '.$structure[$i]['name'];
    echo '<br>perms: '.$structure[$i]['perms'];
    echo '<br>number: '.$structure[$i]['number'];
    echo '<br>owner: '.$structure[$i]['owner'];
    echo '<br>group: '.$structure[$i]['group'];
    echo '<br>size: '.$structure[$i]['size'];
    echo '<br>month: '.$structure[$i]['month'];
    echo '<br>day: '.$structure[$i]['day'];
    echo '<br>time: '.$structure[$i]['time'];
  }
  return $structure;
}

include("footer.php");
switch ($op) {
  case "view":
    echo "<br>IN VIEW<br>";
    view($username, $prev_directory, $curr_directory);
    break;
  default:
    echo "<br>IN DEFAULT<br>";
    view($username, $prev_directory, $curr_directory);
    break;
}
?>
Find all posts by ethanaView user's profileSend private message
ethana
Sergeant
Sergeant


Joined: Dec 26, 2005
Posts: 81


PostPosted: Tue Dec 27, 2005 8:17 am Reply with quoteBack to top

hmm, do i have this in the wrong section? I see 37 views but no responses...i posted this yesterday though it says today (in my time zone)...just curious thinking maybe it needed to be in another section. Thanks.
Find all posts by ethanaView user's profileSend private message
Evaders99
Site Admin
Site Admin


Joined: Aug 17, 2003
Posts: 12389


PostPosted: Tue Dec 27, 2005 5:15 pm Reply with quoteBack to top

Do you have a specific question?

_________________
Helping those that help themselves
Read FIRST or DIE!

"Fighting is terrible, but not as terrible as losing the will to fight."
Star Wars Rebellion Network - Need Help? Evaders Squadron Coding
Find all posts by Evaders99View user's profileSend private messageVisit poster's websiteAIM Address
ethana
Sergeant
Sergeant


Joined: Dec 26, 2005
Posts: 81


PostPosted: Tue Dec 27, 2005 5:45 pm Reply with quoteBack to top

ethana wrote:
Hello all, long time nuke user but first time module writer. I'm porting over one of my web based ftp clients i wrote a while back and im in now playing with the module structure and such. One question i have...and ill use the module Your_Account as an example...is that when i look at the code, i see that it uses $op (registered global) in a switch statement to determine what function to go to and what parameters to pass that function.

My real question is, is that when you first go into Your_Account by clicking on the link under modules...theres no op variable in the query string to tell it where to go...and since there is no op at all the switch statement is not evaluated at all so no default case is ran.

Need to know the methodology behind this so i write my module correctly to fit inside the framework. Thanks for the answers!


My apologies, i was not clear. On the $op variable that i was talking about that determines what function to execute (Your_Account was my example) is not set or even used when you initially go into the Your_Account module when you click on it from under the modules navigation. How is this working then? How does the module know what to execute? Is there a methodology behind this? How do i take my module and make it run a default function even if there is not $op and no switch is evaluated like in Your_Account? I'm assuming theres a standard way of doing this b/c quite a few modules do it. Thanks all and i hope this was clearer!
Find all posts by ethanaView user's profileSend private message
Evaders99
Site Admin
Site Admin


Joined: Aug 17, 2003
Posts: 12389


PostPosted: Tue Dec 27, 2005 10:27 pm Reply with quoteBack to top

Ah I see the problem now. Your code is not correct.

You don't want to call include("footer.php") before your switch statement. That will kill your script before it ever executes the switch

You are better to place the header.php and footer includes in the body of your functions.

i.e.
Code:

<?php
if (!eregi("modules.php", $PHP_SELF)) {
...

function view( ...
  include("header.php");
  ...
  include("footer.php");
}

switch ($op) {
...


I hope that makes sense

_________________
Helping those that help themselves
Read FIRST or DIE!

"Fighting is terrible, but not as terrible as losing the will to fight."
Star Wars Rebellion Network - Need Help? Evaders Squadron Coding
Find all posts by Evaders99View user's profileSend private messageVisit poster's websiteAIM Address
ethana
Sergeant
Sergeant


Joined: Dec 26, 2005
Posts: 81


PostPosted: Wed Dec 28, 2005 6:05 am Reply with quoteBack to top

ok, thats understandable...but still though, what is the standard way for when you first enter a module through the Modules navigation when the link is only modules.php?name=Your_Account and no $op is set in the query string? The switch statement wont evaluate to even run the default b/c of this, or am i wrong? Thanks for your response Smile
Find all posts by ethanaView user's profileSend private message
Evaders99
Site Admin
Site Admin


Joined: Aug 17, 2003
Posts: 12389


PostPosted: Wed Dec 28, 2005 11:27 pm Reply with quoteBack to top

The switch will always go to the default: case then

_________________
Helping those that help themselves
Read FIRST or DIE!

"Fighting is terrible, but not as terrible as losing the will to fight."
Star Wars Rebellion Network - Need Help? Evaders Squadron Coding
Find all posts by Evaders99View user's profileSend private messageVisit poster's websiteAIM Address
ethana
Sergeant
Sergeant


Joined: Dec 26, 2005
Posts: 81


PostPosted: Thu Dec 29, 2005 6:42 am Reply with quoteBack to top

Cool, thanks for the answers...im a Perl guy...much more strict than PHP..well if you include the strict pragma!

Thanks again!
Find all posts by ethanaView user's profileSend private message
Display posts from previous:      
Post new topic  Reply to topicprinter-friendly view
View previous topic Log in to check your private messages View next topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



Powered by phpBB © 2001, 2005 phpBB Group

Ported by Nuke Cops © 2003 www.nukecops.com
:: FI Theme :: PHP-Nuke theme by coldblooded (www.nukemods.com) ::
Powered by · TOGETHER TEAM srl ITALY http://www.togetherteam.it · DONDELEO E-COMMERCE http://www.DonDeLeo.com
Web site engine's code is Copyright © 2002 by PHP-Nuke. All Rights Reserved. PHP-Nuke is Free Software released under the GNU/GPL license.
Page Generation: 0.224 Seconds - 243 pages served in past 5 minutes. Nuke Cops Founded by Paul Laudanski (Zhen-Xjell)
:: FI Theme :: PHP-Nuke theme by coldblooded (www.nukemods.com) ::