<?php
/**
 * @copyright ONE/DEPO Project
 * @license   PHP License 3.01 <http://www.php.net/license/3_01.txt>
 */


/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
 * 画像アップローダ完了
 *
 * @package     Admin.Datamanage.Img.Done
 * @author      netnee <mail@example.com>
 * @access      public
 */
class Admin_Datamanage_Img_Done
{
    var $session;
    var $view;
    var $fileUpload;

    var $title;

    var $m;
    var $c;

    var $type = "o";
    var $div = 4;

    //var $images;
    //var $images1;
    //var $images2;


    function execute()
    {
        $log =& LogFactory::getLog();
        $log->debug("Admin_Datamanage_Img_Doneが実行されました", "Admin_Datamanage_Img_Done#execute");

        $err = false;

        if ($this->m=="del" && isset($this->c)) {
            $this->view->delCacheImage($this->c, 4);
            $this->view->delImage($this->c, 4);

            $this->session->setParameter("flush", "画像が削除されました");
        }


        if ($this->m=="ins") {

        $cd = $this->view->getImageMaxCode(4,"o");
        for ($i=0; $i<3; $i++) {
            $n  = "images";
            $n .= ($i>0) ? $i : "";

            $this->fileUpload->setName($n);
            $count        = $this->fileUpload->count();
            $originalName = $this->fileUpload->getOriginalName();
            $mimeType     = $this->fileUpload->getMimeType();
            $filesize     = $this->fileUpload->getFilesize();

            if (isset($originalName[0]) && $originalName[0]) {
                $pathinfo = pathInfo($originalName[0]);
                $extension = $pathinfo['extension'];
 
                $imgnm = $cd . $this->type.".jpg";
                $dest = IMAGE_DIR ."/". $this->div ."/". $imgnm;
                $log->debug($dest, "Admin_Datamanage_Img_Done#execute");

                if (!is_file($dest) && !$this->fileUpload->move(0, $dest)) {
                    $err = true;

                    $this->session->setParameter("flush", "登録できなかった画像があります。\n確認してください");
                }

            }

            $cd++;
        }
        if ($err===false) $this->session->setParameter("flush", "画像が登録されました");

        }

        if ($err===true) return 'error';
        $loc = htmlspecialchars($_SERVER["SCRIPT_NAME"], ENT_QUOTES) ."?action=admin_datamanage_img";
        header("location: ". $loc);
        exit;
    }

}
?>
