<?php

/*
 * This class is itemdel control class
 */

if (!defined('XOOPS_ROOT_PATH')) exit();

require_once XOONIPS_CONTROL_PATH.'control_base.php';
require_once XOONIPS_MODEL_PATH.'model_fileget.php';

class fileget extends control_base {
  public function init() {
    
  }
  public function run($req) {
    $item_id = $req->get('item_id');
    $file_id = $req->get('file_id');
    if (is_null($item_id) || is_null($file_id) || strlen($item_id) == 0 || strlen($file_id) == 0) {
      $this->rest_notify_err(400, 'Parameter item_id or file_id not specified.');
    }
    $fileget = new model_download();
    $fileget->Init();
    $fileget->set_uid($this->uid);
    $rc = $fileget->download($item_id, $file_id);
    if ($rc == -1) {
      $this->rest_notify_err(403, 'File down load permission denid.', $item_id);
    }
    if ($rc == -2) {
      $this->rest_notify_err(500, 'Illegal file type.', $item_id);
    }    
    if ($rc == -3) {
      $this->rest_notify_err(400, 'Parameter file_id illegal.', $item_id);
    }    
  }
}
