Forums / General Questions / get admin directory

get admin directory

Locked

Views: 1,443

Results 1 to 11 of 11
This thread is locked. New replies are disabled.
11 Dec 2007, 7:47 AM
#1
illusionguy avatar

illusionguy

Zen Follower

Join Date:
May 2007
Posts:
136
Plugin Contributions:
0

get admin directory

Hello guys,

I'm working on a mod and it's going to live in the admin/includes/modules/MYMOD/ folder I would like to know how I would findout the name of the admin folder if a user renames there admin folder name that this mod would still work.

I tride to use DIR_WS_ADMIN but it did not work... Any ideas?

This is the code that I'm trying to use:

 
<img src="' . DIR_WS_ADMIN . 'includes/modules/MYMOD/images/' . $image . '" alt="" />
11 Dec 2007, 10:14 AM
#2
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: get admin directory

That's the right constant, but you may need to prefix it with "HTTP_SERVER . " or "HTTPS_SERVER . "

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

11 Dec 2007, 4:41 PM
#3
illusionguy avatar

illusionguy

Zen Follower

Join Date:
May 2007
Posts:
136
Plugin Contributions:
0

Re: get admin directory

thanks for the reply Kurio,

ok this is what the link looks like when it gets echoed out:

http://www.mydomain.comDIR_WS_ADMINincludes/modules/mymod/images/theimagename.gif

So my guess is that it's not loading the admin configure file, it loads the HTTP_SERVER information but not the DIR_WS_ADMIN

<img src="' . HTTP_SERVER . DIR_WS_ADMIN . 'includes/modules/mymod/images/' . $image . '">

I could include the configure file, but then we are back to square one if the user renames the admin folder lol

So maybe I need to be looking for some php script to lookup the directory that the script is in and go out 3 folders then echo out that folders name. I was hoping for an easier way lol

11 Dec 2007, 4:49 PM
#4
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: get admin directory

It must be loading a configure file or the HTTP_SERVER wouldn't be resolved.

It appears that either it is loading the catalog configure file which doesn't have references to the admin location, or there is a problem with the admin configure file.

Where is the file that is executing this code located?

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

11 Dec 2007, 4:59 PM
#5
illusionguy avatar

illusionguy

Zen Follower

Join Date:
May 2007
Posts:
136
Plugin Contributions:
0

Re: get admin directory

This mod file is in admin/includes/modules/MYMOD/ and it uploads images to ```
admin/includes/modules/MYMOD/images/

 
I think I'm going to rewrite the mod to upload not to the admin/includes/ but just the includes/ folder and save me some hassle.
11 Dec 2007, 5:43 PM
#6
ronlee67 avatar

ronlee67

Totally Zenned

Join Date:
Sep 2006
Location:
Colorado Springs CO USA
Posts:
519
Plugin Contributions:
0

Re: get admin directory

I'm no expert and am taking a risk of egg on my face, but isn't there supposed to be single quotes around DIR_WS_ADMIN?

old:
<img src="' . HTTP_SERVER . DIR_WS_ADMIN . 'includes/modules/mymod/images/' . $image . '">
new:

<img src="' . HTTP_SERVER . 'DIR_WS_ADMIN' . 'includes/modules/mymod/images/' . $image . '">

www.aspenshopsonline.com - ZenCart 1.3.9h
www.wilkssupply.com - ZenCart 1.3.9h
www.un-du.net - ZenCart 1.3.8a

11 Dec 2007, 5:46 PM
#7
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: get admin directory

@ronless67

No. That would change the constant which isn't being properly resolved, into a string which would never be resolved.

@IllusionGuy

How about the admin configure file? Are other parts of admin working correctly? Is there a typo in or around the declaration of the DIR_WS_ADMIN?

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

11 Dec 2007, 6:58 PM
#8
ronlee67 avatar

ronlee67

Totally Zenned

Join Date:
Sep 2006
Location:
Colorado Springs CO USA
Posts:
519
Plugin Contributions:
0

Re: get admin directory

I knew I would get egg on my face. I figured that out before my 7 minutes to edit ran out, but wasted my time trying to figure out how to delete my post altogether. (Never figured out). So it went through anyway.

I agree the answer probably lies in the admin/configuration.php file.

www.aspenshopsonline.com - ZenCart 1.3.9h
www.wilkssupply.com - ZenCart 1.3.9h
www.un-du.net - ZenCart 1.3.8a

11 Dec 2007, 7:02 PM
#9
illusionguy avatar

illusionguy

Zen Follower

Join Date:
May 2007
Posts:
136
Plugin Contributions:
0

Re: get admin directory

I'm sure the config file is setup right becuase the store and the admin panel both work great, I'm sure it's this mod that I'm working on.

The following code that is the script from a file called "testimonials_display.php".

<?PHP
@mysql_connect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD) or die("Unable to connect");
@mysql_select_db(DB_DATABASE) or die("Unable to select database DB_DATABASE");
$query=("SELECT image, business_name, location, LEFT(quote,300) AS quote FROM " . DB_PREFIX . "testimonials")or die(@mysql_error());
$result=mysql_query($query);
$num=mysql_numrows($result);
$i=0;
while ($i < $num) {
$image=mysql_result($result,$i,"image");
$quote=mysql_result($result,$i,"quote");
$business_name=mysql_result($result,$i,"business_name");
$location=mysql_result($result,$i,"location");
if (empty($image)){$image = "default.gif";}
$quotes[] = '
 <div><img src="'. DIR_WS_ADMIN .'includes/modules/testimonials/testimonial_images/' . $image . '" alt="" /></div>
 <div style="font-size:10px; padding-right:8px;">"<em>' . $quote . '</em>"... <a href="index.php?main_page=testimonials&session=display" style="white-space:nowrap;">Read More »</a></div>
 <div /><p><strong>' . $business_name . '</strong><br />
 ' . $location . '</p>';
$i++;
};
srand ((double) microtime() * 1000000);
$testimonials = rand(0,count($quotes)-1);
echo $quotes[$testimonials];
?>

That is the only code that I have in the file I'm not sure but I may be missing something that needs to include the right config file.

This testimonials mod has tools for the admin panel and it's own page and sidebox for the front end, so there is a lot going on with a lot of diffrent files.

I was playing around with
```php
(dirname(FILE) . '/testimonial_images/')

And it seems to work for the files in the admin but it’s not going to work for the files that are in the includes folder, so to save some time I’m just going to change the image folder to be in includes/modules/testimonials/images/ folder
11 Dec 2007, 10:57 PM
#10
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: get admin directory

Why not use the Zen Cart database wrapper for your queries?

How is this script called? In particular, what includes application_top which co-ordinates the loading of all the components that make up a Zen Cart page in the admin?

Finally, as an aside, rather than building a file structure with admin as it's root, why not just look down one level from your script into the images file?

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

12 Dec 2007, 12:12 AM
#11
illusionguy avatar

illusionguy

Zen Follower

Join Date:
May 2007
Posts:
136
Plugin Contributions:
0

Re: get admin directory

kuroi:

Why not use the Zen Cart database wrapper for your queries? I did not know you could, I'm still learning as I go :smartalec:

kuroi:

How is this script called? In particular, what includes application_top which co-ordinates the loading of all the components that make up a Zen Cart page in the admin?
Ok like I mentioned before I really do not have any clue to what I'm doing lol, I took a look at other mods that where under tools in the admin panel to see how they where called. I think this is the file that is calling the admin page part of it is.

<?php
 
  require('includes/application_top.php');
  function zen_display_files() {
    global $check_directory, $found, $configuration_key_lookup;
    for ($i = 0, $n = sizeof($check_directory); $i < $n; $i++) {
//echo 'I SEE ' . $check_directory[$i] . '<br>';
      $dir_check = $check_directory[$i];
      $file_extension = '.php';
      if ($dir = @dir($dir_check)) {
        while ($file = $dir->read()) {
          if (!is_dir($dir_check . $file)) {
            if (substr($file, strrpos($file, '.')) == $file_extension) {
              $directory_array[] = $file;
            }
          }
        }
        if (sizeof($directory_array)) {
          sort($directory_array);
        }
        $dir->close();
      }
    }
    return $directory_array;
  }
  $action = (isset($_GET['action']) ? $_GET['action'] : '');
  $za_who = $_GET['za_lookup'];
  if ($action == 'new_page') {
    $page = $_GET['define_it'];
    $check_directory = array();
    $check_directory[] = DIR_FS_CATALOG . DIR_WS_LANGUAGES . $_SESSION['language'] . '/html_includes/';
    $directory_files = zen_display_files();
    $za_lookup = array();
    for ($i = 0, $n = sizeof($directory_files); $i < $n; $i++) {
      $za_lookup[] = array('id' => $i, 'text' => $directory_files[$i]);
    }
// This will cause it to look for 'define_conditions.php'
    $_GET['filename'] = $za_lookup[$page]['text'];
    $_GET['box_name'] = BOX_TOOLS_DEFINE_CONDITIONS;
  }
// define template specific file name defines
  $file = zen_get_file_directory(DIR_FS_CATALOG_LANGUAGES . $_SESSION['language'] . '/html_includes/', $_GET['filename'], 'false');
?>
<?php
  switch ($_GET['action']) {
      case 'set_editor':
        // Reset will be done by init_html_editor.php. Now we simply redirect to refresh page properly.
        $action='';
        zen_redirect(zen_href_link(FILENAME_DEFINE_PAGES_EDITOR));
        break;
    case 'save':
      if ( ($_GET['lngdir']) && ($_GET['filename']) ) {
        if (file_exists($file)) {
          if (file_exists('bak' . $file)) {
            @unlink('bak' . $file);
          }
          @rename($file, 'bak' . $file);
          $new_file = fopen($file, 'w');
          $file_contents = stripslashes($_POST['file_contents']);
          fwrite($new_file, $file_contents, strlen($file_contents));
          fclose($new_file);
        }
        zen_redirect(zen_href_link(FILENAME_DEFINE_PAGES_EDITOR));
      }
      break;
  }
  if (!$_SESSION['language']) $_SESSION['language'] = $language;
  $languages_array = array();
  $languages = zen_get_languages();
  $lng_exists = false;
  for ($i=0; $i<sizeof($languages); $i++) {
    if ($languages[$i]['directory'] == $_SESSION['language']) $lng_exists = true;
    $languages_array[] = array('id' => $languages[$i]['directory'],
                               'text' => $languages[$i]['name']);
  }
  if (!$lng_exists) $_SESSION['language'] = $language;
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
<link rel="stylesheet" type="text/css" href="includes/cssjsmenuhover.css" media="all" id="hoverJS">
<script language="javascript" src="includes/menu.js"></script>
<script language="javascript" src="includes/general.js"></script>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF" onLoad="init()">
<div id="spiffycalendar" class="text"></div>
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->
<?PHP include "includes/modules/testimonials/testimonials.php"; ?>
<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
<br />
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>

kuroi:

Finally, as an aside, rather than building a file structure with admin as it's root, why not just look down one level from your script into the images file? This would work for the files that are in the admin section but for the other files that I have under the includes section they need to know what the admin folder is called.