File.php 1.33 KB
Newer Older
Carsten  Rose's avatar
Carsten Rose committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
/**
 * Created by PhpStorm.
 * User: crose
 * Date: 4/25/16
 * Time: 10:39 PM
 */

namespace qfq;

require_once(__DIR__ . '/store/Store.php');
require_once(__DIR__ . '/Constants.php');

class File {

    /**
     * @var null|Store
     */
    private $store = null;

    public function __construct($phpUnit = false) {
        $this->store = Store::getInstance('', $phpUnit);
    }

    public function process() {

        $sClient = $this->store->getVar(CLIENT_SIP, STORE_CLIENT, SANITIZE_ALLOW_ALNUMX);
        $sStore = $this->store->getVar(SIP_SIP, STORE_SIP);
        if ($sClient === false || $sStore === false || $sClient !== $sStore) {
            throw new UserFormException('SIP invalid', ERROR_SIP_INVALID);
        }

        $uploadFeName = $this->store->getVar(CLIENT_UPLOAD_FE_NAME, STORE_CLIENT, SANITIZE_ALLOW_ALNUMX);
        $uploadDelete = $this->store->getVar(CLIENT_UPLOAD_DELETE, STORE_CLIENT, SANITIZE_ALLOW_ALNUMX);

        $newArr = $_FILES;
        $oldArr = $this->store->getVar($uploadFeName . STORE_EXTRA, SANITIZE_ALLOW_ALL);
        if (isset($oldArr[EXTRA_UPLOAD_DELETE]) && $oldArr[EXTRA_UPLOAD_DELETE] === 'yes') {
            $uploadDelete = 'yes';
        }

        if ($uploadDelete === 'yes')
            $newArr[EXTRA_UPLOAD_DELETE] = 'yes';

        $this->store->setVar($uploadFeName, $newArr, STORE_EXTRA);
    }
}