<?php

if ( ! @include_once( './mainfile.php' ) ) { exit( '!! INCLUDE ERROR. ACCESS DENIED !!' ); }
error_reporting( _E_VALUE );


/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | myPHPNuke Version 188_8 RC2                                          |
// +----------------------------------------------------------------------+
// | License: GNU/GPL - http://www.gnu.org/copyleft/gpl.html              |
// +----------------------------------------------------------------------+
// | Support: http://myphpnuke.com/                                       |
// +----------------------------------------------------------------------+
// | Author: myPHPNuke Dev Team                                           |
// +----------------------------------------------------------------------+
// | Copyright: © 2001-2004 myPHPNuke Dev Team                            |
// +----------------------------------------------------------------------+
// $Id: editmedia.php,v 1.5.2.2 2004/04/18 12:46:51 ajvwaay Exp $




function editmedia($gid) {
    global
            $adminurl,
        $module_name,
        $gallerypath,
        $imagepath,
        $adminpath,
        $languagepath,
        $baseurl,
        $adminurl, $mpnTables, $textcolor1;
            ;
    global $version, $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4;
    global $offset, $thumbnailwidth;

#   include ("header.php");
    include("$adminpath/fileFunctions.php");
#   GraphicAdmin($hlpfile);
    OpenTable();
    echo "<center><font size=\"4\"><b>"._GALADMIN."</b></font></center>";
    CloseTable();
    echo "<br>";
    OpenTable();
    echo "<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr><td>";

    echo "
    <form method=\"POST\" action=\"$adminurl\">
        <input type=\"hidden\" name=\"op\" value=\"doeditmedia\">
        <input type=\"hidden\" name=\"type\" value=\"existing\">
        <!--<input type=\"hidden\" name=\"Category\" value=\"$gid\">-->
            <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">
            <tr>
            <td align=\"left\">
                <font face=\"Verdana, Arial\" size=\"1\">
                <a href=\"$adminurl\"><b>"._GALCONFIG."</b></a> &gt;
                <a href=\"$adminurl&amp;op=maineditmedia\"><b>"._GALVIEWMEDIA."</b></a> &gt;
                <b>"._GALEDITEXISTINGMEDIA."</b>
                </font>
            </td>
            <td align=\"right\">
                <font face=\"Verdana, Arial\" size=\"1\">
                [<a href=\"$adminurl&amp;op=doeditmedia&amp;type=new\">"._GALADDMEDIA."</a>]
                </font>
            </td>
            </tr>
            </table>
        </td>
      </tr>
      <tr>";
    $sql = "SELECT gallname FROM ".$mpnTables['gallery_categories']." WHERE gallid=$gid";
    list ($gallname) = mysql_fetch_row(mysql_query($sql));

    $sql = "SELECT count(*) FROM ".$mpnTables['gallery_pictures']." WHERE gid=$gid";
    $result = mysql_query($sql);

    $limit = 5;
    echo "<input type=\"hidden\" name=\"limit\" value=\"$limit\">";
    list($numrows) = mysql_fetch_row($result);

    if ($numrows>0) {

        if (!isset($offset) || $offset=="") {
                    $offset=0;
            }
        $pages = intval($numrows/$limit);

        $sql = "SELECT p.pid, p.gid, c.galloc, p.img, p.counter, p.submitter, p.date, p.name, p.description, p.votes, p.rate, p.width, p.height FROM ".$mpnTables['gallery_pictures']." p, ".$mpnTables['gallery_categories']." c WHERE p.gid=$gid and p.gid=c.gallid limit $offset, $limit";
        //echo $sql;
        $res = mysql_query($sql);

        if ($numrows%$limit) {
                $pages++;
        }

        $nav = null;

        for ($i=1;$i<=$pages; $i++) {
                $newoffset=$limit*($i-1);
                if ($newoffset==$offset) {
                    $nav .= "[$i]";
                    $end = $limit*$i;
                    if ($end>$numrows)
                        $end = $numrows;
                }
                else {
                    $nav .= "[<a href=\"$adminurl&op=editmedia&type=edit&category=$gid&offset=$newoffset\">$i</a>]";
                }
        }
        $deb = $offset+1;

         echo "
            <td width=\"100%\" align=\"center\">"._GALDISPLAYMEDIAIN." $gallname<br>
            "._GALNOWDISPLAYFILES." $deb - $end of $numrows<br>
            "._GALJUMP2PAGE." $nav
            </td>
        </tr>";
        $i=0;

        while (list($pid, $gid, $galloc, $img, $counter, $submitter, $date, $name, $description, $votes, $rate, $width, $height) = mysql_fetch_array($res)) {
        echo "
        <tr>
            <td width=\"100%\">
            <table border=\"0\" cellpadding=\"5\" cellspacing=\"0\">
            <tr>
                    <td>
                    <a href=\"$gallerypath/$galloc/$img\" target=\"_new\">";

                    $image = "$gallerypath/$galloc/$img";
                        $thumb_dir = "$gallerypath/$galloc/thumb";
                    $thumb = "$thumb_dir/$img";
                    if(!file_exists($thumb))
                        {
                            if (!file_exists($thumb_dir)) {
                                makeDir("$gallerypath/$galloc", "thumb");
                        }
                        $thumb = RatioResizeImg( $image, $thumb, $thumbnailwidth);
                    }
                    $thumb = getThumbnail($img, $galloc);
                    // Remplacer par le default icon

                    print '<img src="'.$thumb.'" alt="'.$name.'" width="'.$thumbnailwidth.'" border="1">';
                    echo"
                    </a><br>
                        <font size=\"1\" face=\"Verdana, Arial\">"._GALFILENAME."</font><br>
                    <font size=\"1\" face=\"Verdana, Arial\">$img</font><br>
                    <input type=\"hidden\" name=\"FileName$i\" size=\"14\" value=\"$img\">
                    <input type=\"hidden\" name=\"FileId$i\" size=\"14\" value=\"$pid\">
                    <font size=\"1\" face=\"Verdana, Arial\">
                    <INPUT TYPE=\"radio\" NAME=\"Task$i\" VALUE=\"Save\" checked><small>"._GALSAVECHANGES."</small><br>
                    <INPUT TYPE=\"radio\" NAME=\"Task$i\" VALUE=\"Delete\"><small>"._GALDELETE."</small>
                </td>
                <td align=\"left\" valign=\"top\">
                    <font size=\"1\" face=\"Verdana, Arial\">"._GALSELECTCATEGORY."</font><br>
                    <input type=\"hidden\" name=\"OldCategory$i\" size=\"14\" value=\"$gid\">
                            <select size=\"1\" name=\"Category$i\">";

                    $categories = listcategories("$gallerypath");
                    $categories = explode(" ", trim($categories));
                    while(list($key, $val) = each($categories)) {
                        $result = mysql_query("select gallid, gallname, parent from ".$mpnTables['gallery_categories']." where gallid=".$val);
                        list($gallid, $gallname, $parent) = mysql_fetch_row($result);
                        $nbtabs = indent($gallid);
                        $tab = "";
                        for ($j=0; $j<$nbtabs; $j++)
                            $tab .= "&nbsp;&nbsp;";
                        if ($gallid==$gid)
                            echo "<option selected value=\"$gallid\">$tab$gallname</option> ";
                        else
                            echo "<option value=\"$gallid\">$tab$gallname</option> ";
                     }
                    echo "  </select><br>
                    <font size=\"1\" face=\"Verdana, Arial\">"._GALWIDTHXHEIGHT."</font><br>
                    <input type=\"text\" name=\"Width$i\" size=\"4\" value=\"$width\"> x <input type=\"text\" name=\"Height$i\" size=\"4\" value=\"$height\"><br>
                    <font size=\"1\" face=\"Verdana, Arial\">"._GALMEDIANAME."<br></font>
                    <input type=\"text\" name=\"MediaName$i\" size=\"14\" value=\"$name\"><br>
                        <font size=\"1\" face=\"Verdana, Arial\">"._GALDATEADDED."<br></font>
                    <input type=\"text\" name=\"Date$i\" size=\"14\" value=\"$date\"><br>
                        <font size=\"1\" face=\"Verdana, Arial\">"._GALSUBMITTER."</font><br>
                    <input type=\"text\" name=\"Submitter$i\" size=\"14\" value=\"$submitter\"><br>
                            <font size=\"1\" face=\"Verdana, Arial\">
                        "._GALHITS." $counter<br>
                        "._GALVOTES." $votes<br>
                        "._GALRATING." $rate</font>
                </td>
                <td align=\"left\" valign=\"top\" width=\"609\">
                    <font size=\"1\" face=\"Verdana, Arial\">"._GALDESCRIPTION."</font><br>
                        <textarea  name=\"Description$i\" rows=\"9\" cols=\"25\">$description</textarea>
                </td>
            </tr>
                </table>
            </td>
        </tr>";
        $i++;
        } //while
        echo "
        <tr>
            <td align=\"center\">
                <input class=\"button\" type=\"submit\" value=\""._SAVECHANGES."\" name=\"add\">
        </form>";
    }
    else
        echo "<tr><td align=\"center\"></form><br>"._GALNOMEDIAFOUND."<br>";
    echo "</td></tr></table>";
    CloseTable();
    print '<br>';
    // Start Of Footer
    // Start Of Footer
    OpenTable();
    print '
    <table><tr>
    <td>'
      ."<font face=\"Verdana,Arial\" color=\"$textcolor1\">mpn eGallery Version - $version<br>"._GALVISITUPDATE.'</font>
    </td>
    </tr></table>';
    CloseTable();
#   include("footer.php");
}

?>
