Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP
Author Message
killing-hours
RavenNuke(tm) Development Team



Joined: Oct 01, 2010
Posts: 438
Location: Houston, Tx

PostPosted: Wed Dec 29, 2010 12:27 pm Reply with quote

Hey all-

hitting a snag with the put in home part of the modules admin and not understanding the intentions behind a bit of code. Just need someone to explain it in "lays" terms to me please.


Code:
      case 'ajaxHome_module':

      csrf_check();
      isset($_GET['mid']) ? $mid = intval($_GET['mid']) : header('Location: ' . $admin_file . '.php?op=ajaxModules');
      isset($_GET['ok']) ? $ok = intval($_GET['ok']) : $ok = 0; //Should be 0 or 1
      ajaxHome_module($mid, $ok);
      break;


This bit of code is for when you click on "yes" in the put modules in home. I'm not really understanding the intentions behind the (isset($_GET['mid'] ?) & the "OK" isset other than it's to see if the variable has been set???

I've removed the links (yes | no) and replaced them with a button that submits the data (using hidden values) via the jquery .ajax method. In doing so... I believe i've altered the way this "isset" should behave but I'm not understanding what the point of it was so that I can put the check or w/e back in place.

If I comment out those two lines... everything works as intended... however, If I leave those lines in place... I never seem to make it to the database update part of the function. (specifically I believe it's the $mid that is causing the problem because of the redirect I get in firebug)

here is the modified function:
Code:
function ajaxHome_module($mid, $ok=0) {

global $prefix, $db, $admin_file;
   if ($ok == 0) {
      OpenTable();
      $row = $db->sql_fetchrow($db->sql_query('SELECT title from ' . $prefix . '_modules WHERE mid=\''.$mid.'\''));
      $new_m = $row['title'];
      $row2 = $db->sql_fetchrow($db->sql_query('SELECT main_module from ' . $prefix . '_main'));
      $old_m = $row2['main_module'];
      echo '<form id="pHomef">';
      echo '<input type="hidden" value="'.$mid.'" name="mid">';
      echo '<input type="hidden" value="1" name="ok">';
      echo csrf_rn_token('input');
      echo '</form>';
      echo '<center><b>' . _DEFHOMEMODULE . '</b><br /><br />'
         .'' . _SURETOCHANGEMOD . ' <b>'.$old_m.'</b> ' . _TO . ' <b>'.$new_m.'</b>?<br /><br />';
      echo '<center><input type="button" id="pCommit" value="Commit" /></center>';
      CloseTable();
   } else {
      $row3 = $db->sql_fetchrow($db->sql_query('SELECT title FROM ' . $prefix . '_modules WHERE mid=\''.$mid.'\''));
      $title = $row3['title'];
      $active = 1;
      $view = 0;
      $res = $db->sql_query('UPDATE ' . $prefix . '_main SET main_module=\''.$title.'\'');
      $res2 = $db->sql_query('UPDATE ' . $prefix . '_modules SET active=\''.$active.'\', view=\''.$view.'\' where mid=\''.$mid.'\'');
      //Header('Location: '.$admin_file.'.php?op=modules');
   }
}




This is the original code:
Code:
function home_module($mid, $ok=0) {

   global $prefix, $db, $admin_file;
   if ($ok == 0) {
      include_once('header.php');
      GraphicAdmin();
      title('' . _HOMECONFIG . '');
      OpenTable();
      $row = $db->sql_fetchrow($db->sql_query('SELECT title from ' . $prefix . '_modules WHERE mid=\''.$mid.'\''));
      $new_m = $row['title'];
      $row2 = $db->sql_fetchrow($db->sql_query('SELECT main_module from ' . $prefix . '_main'));
      $old_m = $row2['main_module'];
      echo '<center><b>' . _DEFHOMEMODULE . '</b><br /><br />'
         .'' . _SURETOCHANGEMOD . ' <b>'.$old_m.'</b> ' . _TO . ' <b>'.$new_m.'</b>?<br /><br />'
         .'[ <a class="rn_csrf" href="'.$admin_file.'.php?op=home_module&amp;mid='.$mid
         .'&amp;ok=1">' . _YES . '</a> | <a href="'.$admin_file.'.php?op=modules">' . _NO . '</a> ]</center>';
      CloseTable();
      include_once('footer.php');
   } else {
      $row3 = $db->sql_fetchrow($db->sql_query('SELECT title FROM ' . $prefix . '_modules WHERE mid=\''.$mid.'\''));
      $title = $row3['title'];
      $active = 1;
      $view = 0;
      $res = $db->sql_query('UPDATE ' . $prefix . '_main SET main_module=\''.$title.'\'');
      $res2 = $db->sql_query('UPDATE ' . $prefix . '_modules SET active=\''.$active.'\', view=\''.$view.'\' where mid=\''.$mid.'\'');
      Header('Location: '.$admin_file.'.php?op=modules');
   }
}


-------------

If I'm "POSTING" data back to the function with the values from the form... does it really matter if the isset is even in place??

_________________
Money is the measurement of time - Me
"You can all go to hell…I’m going to Texas" -Davy Crockett 
View user's profile Send private message
Palbin
Site Admin



Joined: Mar 30, 2006
Posts: 2583
Location: Pittsburgh, Pennsylvania

PostPosted: Wed Dec 29, 2010 1:15 pm Reply with quote

Yes, is the short answer.

Change the four instances of $_GET to $_POST. I will try and post an explanation of everything else later.

_________________
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan. 
View user's profile Send private message
killing-hours







PostPosted: Wed Dec 29, 2010 1:18 pm Reply with quote

Palbin-

I tried changing to the "$_POST" method but it never seemed to get me where I needed to. I'm going to create a screencast of what's going on so you can see what is actually happening in firebug. Hold off on your explanation until I show you so you don't waste precious time. Thanks for the quick reply!
 
Palbin







PostPosted: Wed Dec 29, 2010 2:16 pm Reply with quote

Also post the jQuery you are using to submit the form data.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP

View next topic
View previous 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
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©